ImportError: No module named gi.repository Mac OS X

MKT picture MKT · Aug 8, 2013 · Viewed 20.3k times · Source

I am installing virt-manager0.10.0 on Mac OS X

First I installed python,libvirt, gtk+3, pygtk, and other dependencies with homebrew

But when I run virt-manager I got this error

from gi.repository import GObject
ImportError: No module named gi.repository

When I run this import in python command line I get same error.but there is no error when I try import gtk

I think the problem is the homebrew pygtk version doesn't use gtk+3 and uses gtk2 and as we can see here gi.repository Windows only gtk+3 use that syntax.

Answer

kikap picture kikap · Oct 18, 2015

The gi module is in the pygobject package but if you install this package on OS/X, you won't get the gi module. To really install gi on OS/X you need to install pygobject3 module which may look like it's for Python3 but it's not, the 3 comes from GTK version. So if you're on the OS/X, the simple brew install pygobject3 will do the trick.