Install gobject module?
Solution 1
Install python3-gi
and import it this way
from gi.repository import GObject
or so you don't have to rename all the references
from gi.repository import GObject as gobject
Solution 2
Pip does not have it anymore. Check out the 'Getting Started' section here and install it based on your OS.
For accessibility, based on this question's tags, here's the "Ubuntu" section:
Installing the system provided PyGObject:
- Open a terminal
- Execute
sudo apt install python3-gi python3-gi-cairo gir1.2-gtk-3.0
- Change the directory to where your hello.py script can be found (e.g.
cd Desktop
)- Run
python3 hello.py
Installing from PyPI with pip:
- Open a terminal and enter your virtual environment
- Execute
sudo apt install libgirepository1.0-dev gcc libcairo2-dev pkg-config python3-dev gir1.2-gtk-3.0
to install the build dependencies and GTK- Execute
pip3 install pycairo
to build and install Pycairo- Execute
pip3 install PyGObject
to build and install PyGObject- Change the working directory to where your
hello.py
script can be found- Run
python3 hello.py
Comments
-
MarAja about 4 years
I want to work with the dbus-python library (I just pip installed it) and they provide some nice example about making two programs communicate. In one of their .py file there is an "import gobject" line which results in a "ImportError: No module named gobject" when I run this example. I would like to know what I should install to get this module (I am working with Python3 on an Ubuntu).
When I use python2.7 this import is working and the gobject.
__file__
variable contains:/usr/lib/python2.7/dist-packages/gobject/__init__.pyc