Can not import modules from gi.repository

John Slathon picture John Slathon · Sep 16, 2014 · Viewed 10.7k times · Source

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!

Answer

ptomato picture ptomato · Sep 17, 2014

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.