Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can not import modules from gi.repository

I can not import modules from gi.repository. Specifically not Gtk and GObject.

I experienced this error both on Ubuntu 14.04 LTS and after reinstall also on Linux Mint 17.

from gi.repository import Gtk, GObject

Results in the 'unresolved reference' warning for the respective modules. Interestingly enough my Gtk GUI can be compiled and works perfectly fine. Yet, GObject is entirely out of function.

I tried to work around with altering import statements such as:

from gi.repository.Gtk import*

Even hard coding the import path via:

sys.path.append('/usr/lib/python2.7/dist-packages/gi')

None of these approaches have solved this frustrating error so far.

I have not found any concluding help or basic info on this issue, neither anywhere on the web nor in Linux forums or here on stackoverflow. I am not sure whether this problem lies on the Python or the Linux side of things.

Can anybody suggest how to solve this issue? What additional information do I need to provide eventually.

Thanks!

like image 782
John Slathon Avatar asked Sep 16 '14 12:09

John Slathon


People also ask

What is GI module in Python?

The require_version method ensures the namespace gets loaded with the given version. The gi. repository is the Python module for PyGObject . PyGObject (Python GObject introspection) contains Python bindings and support for GObject, GLib, GTK and other libraries. $ ./version.py 4.6.5.

How do I import PyGObject?

Open a terminal and enter your virtual environment. Execute sudo zypper install cairo-devel pkg-config python3-devel gcc gobject-introspection-devel 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.

What is GI repository?

gi. repository is the Python module for PyGObject (which stands for Python GObject introspection) which holds Python bindings and support for the GTK+ 3 toolkit and for the GNOME apps.


2 Answers

If on a Debian-based system such as Ubuntu, you probably need to install the gir1.2-gtk-3.0 package and other similarly named packages for other libraries. I don't know what the name of the package would be on Mint, but it's probably something similar.

like image 144
ptomato Avatar answered Oct 17 '22 19:10

ptomato


On Wheezy (Debian 7.8) installing python3-gi fixed the problem for me.

like image 21
Ian Cairns Avatar answered Oct 17 '22 20:10

Ian Cairns