ImportError: No module named gi.repository Mac OS X

為{幸葍}努か 提交于 2020-01-22 18:58:44

问题


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.


回答1:


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.




回答2:


pyGTK is for GTK 2 only. If you want the python bindings for GTK 3, you need to install pyGObject. See https://stackoverflow.com/a/9672426/518853




回答3:


The python3 bindings for GTK3 can be installed with brew install pygobject3 --with-python3 or brew reinstall pygobject3 --with-python3




回答4:


Did you use the built Python or the one that home brew installed to /opt/python/ ? issue which python in your term. Then in python issue import sys; print sys.path.



来源:https://stackoverflow.com/questions/18119618/importerror-no-module-named-gi-repository-mac-os-x

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!