'Install gobject module?

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


Solution 1:[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:[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:

  1. Open a terminal
  2. Execute sudo apt install python3-gi python3-gi-cairo gir1.2-gtk-3.0
  3. Change the directory to where your hello.py script can be found (e.g. cd Desktop)
  4. Run python3 hello.py

Installing from PyPI with pip:

  1. Open a terminal and enter your virtual environment
  2. 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
  3. Execute pip3 install pycairo to build and install Pycairo
  4. Execute pip3 install PyGObject to build and install PyGObject
  5. Change the working directory to where your hello.py script can be found
  6. Run python3 hello.py

Solution 3:[3]

I resolve problem on Centos 7 , when install pygobject2.x86_64

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 pacholik
Solution 2 Christian Reall-Fluharty
Solution 3 bungeeMK