如何让python识别/找到自制软件安装的gi.repository(PyGObjects)?

时间:2013-10-03 10:38:02

标签: python osx-mountain-lion homebrew gtk3 pygobject

当我从“gi.repository import Gtk”输入解释器时,我得到了

    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ImportError: No module named gi.repository

这是我的brew列表

at-spi2-atk freetype    gtk+        libffi      py2cairo
at-spi2-core    gdbm        gtk+3       libpng      pygobject
atk     gdk-pixbuf  harfbuzz    libtiff     pygtk
cairo       gettext     icu4c       pango       readline
d-bus       glib        intltool    pixman      sqlite
fontconfig  gstreamer   jpeg        pkg-config  xz

python中“print sys.path”的结果

['', '/Library/Python/2.7/site-packages/setuptools-1.1.5-py2.7.egg', '/Library/Python/2.7/site-packages/py2app-0.7.3-py2.7.egg', '/Library/Python/2.7/site-packages/macholib-1.5.1-py2.7.egg', '/Library/Python/2.7/site-packages/modulegraph-0.10.4-py2.7.egg', '/Library/Python/2.7/site-packages/altgraph-0.10.2-py2.7.egg', '/usr/local/lib/python2.7/site-packages', '/usr/local/lib/python2.7/site-packages/gobject', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python', '/Library/Python/2.7/site-packages', '/usr/local/lib/python2.7/site-packages/gtk-2.0']

我的自制模块的网站包似乎在python路径中,所以我不知道我错过了什么。我正在使用我的System / Library / Frameworks目录中的python 2.7.5(在Mountain Lion上)。我尝试使用python(2和3)来尝试对此进行排序,但是安装会在python以100%cpu运行并且永远不会完成时停止运行。

提前感谢你提出的任何建议。

1 个答案:

答案 0 :(得分:1)

您需要将环境变量GI_TYPELIB_PATH设置为girepository-1.0目录的路径,该路径应包含您要使用的每个库的.typelib个文件。我想象

export GI_TYPELIB_PATH=/usr/local/lib/girepository-1.0

或类似的东西在Bash中起作用。

如果情况并非如此,您还需要确保内省运行时可以找到共享库。这可以通过适当设置LD_LIBRARY_PATH环境在Linux上完成,例如:

export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH

Apple's documentation建议LD_LIBRARY_PATH也适用于Mac,但我还没有尝试过。