3

When I input "from gi.repository import Gtk" into the interpreter I get

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

Here is my brew list

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

And the results of "print sys.path" in python

['', '/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']

The site-packages for my homebrewed modules appear to be in the python path so I have no idea what I'm missing. I am using the python 2.7.5 (on Mountain Lion) which is in my System/Library/Frameworks directory. I have tried brewing python (2 and 3) to try to sort this out but the install stalls with python running at 100% cpu and never finishing.

Thanks in advance for any advice you might have.

Will03
  • 145
  • 1
  • 9

1 Answers1

1

You need to set the environment variable GI_TYPELIB_PATH to the path of your girepository-1.0 directory, which should include .typelib files for every library you want to use. I'd imagine

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

or something very similar will work in Bash.

You'll also need to make sure that the shared libraries are locatable by the introspection runtime, if that's not the case already. This can be accomplished on Linux by setting the LD_LIBRARY_PATH environment appropriately, for example:

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

Apple's documentation suggests LD_LIBRARY_PATH should also work on a Mac, but I haven't tried it.

Tristan Brindle
  • 16,281
  • 4
  • 39
  • 82
  • Thank you for the answer. Unfortunately, there doesn't seem to be a girepository-1.0 directory in OSX. I have since switched to Qt but I do appreciate the help. – Will03 Oct 09 '13 at 00:51
  • "brew install pygobject3" will create "/usr/local/lib/girepository-1.0" – Anuj Feb 01 '16 at 10:06
  • @Tristan Brindle, I have the "/usr/local/lib/girepository-1.0" directory, but the two export commands didn't help me. please see my question here: https://stackoverflow.com/questions/54515203/cannot-import-gi-module-python-3-6-on-mac – Cindy Feb 04 '19 at 13:59