简体   繁体   English

ImportError:没有名为gi.repository Mac OS X的模块

[英]ImportError: No module named gi.repository Mac OS X

I am installing virt-manager0.10.0 on Mac OS X 我在Mac OS X上安装virt-manager0.10.0

First I installed python,libvirt, gtk+3, pygtk, and other dependencies with homebrew 首先我用自制软件安装了python,libvirt,gtk + 3,pygtk和其他依赖项

But when I run virt-manager I got this error 但是当我运行virt-manager时,我遇到了这个错误

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 当我在python命令行中运行此导入时,我得到相同的错误。但是当我尝试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. 我认为问题是自制的pygtk版本不使用gtk + 3并使用gtk2,因为我们可以在这里看到gi.repository Windows只有gtk + 3使用该语法。

The gi module is in the pygobject package but if you install this package on OS/X, you won't get the gi module. gi模块位于pygobject包中,但如果在OS / X上安装此软件包,则无法获得gi模块。 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. 要在OS / X上真正安装gi ,你需要安装pygobject3模块,它可能看起来像是Python3,但事实并非如此, 3来自GTK版本。 So if you're on the OS/X, the simple brew install pygobject3 will do the trick. 因此,如果您使用的是OS / X,那么简单的brew install pygobject3就可以解决问题。

可以使用brew install pygobject3 --with-python3brew reinstall pygobject3 --with-python3的python3绑定

pyGTK is for GTK 2 only. pyGTK仅适用于GTK 2。 If you want the python bindings for GTK 3, you need to install pyGObject. 如果你想要GTK 3的python绑定,你需要安装pyGObject。 See https://stackoverflow.com/a/9672426/518853 请参阅https://stackoverflow.com/a/9672426/518853

Did you use the built Python or the one that home brew installed to /opt/python/ ? 您是否使用构建的Python或家庭brew安装到/opt/python/ issue which python in your term. 在你的学期中发出which python Then in python issue import sys; print sys.path 然后在python中import sys; print sys.path import sys; print sys.path . import sys; print sys.path

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM