Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Install PyGTK via Homebrew and virtualenv
# This LOOKS pretty straightforward, but it took awhile to sort out issues with
# py2cairo and pygobject, so I hope I've saved you some time :-)
# This assumes you already subscribe to a nice clean virtualenvwrapper workflow
# -- see if you need advice on getting there.
# There are some optional dependencies omitted, so if you're going to be doing
# heavy development with these libs, you may want to look into them.
# We go to some configure option pains to avoid polluting the system-level
# Python, and `brew link`ing Cairo which is keg-only by default.
brew install cairo && brew install gtk+
# Have a coffee. Better yet, a meal.
mkvirtualenv --no-site-packages pygtk
workon pygtk
# NOTE: pycairo uses a nonstandard build system, the autotools approach is
# officially unsupported. I couldn't get the latest version (1.10.0 at time of
# writing) to work with either approach, so I punted and used autotools here
# with the next-most-recent version.
curl -O
tar xzf py2cairo-1.8.10.tar.gz && cd py2cairo-1.8.10
./configure --prefix=$VIRTUAL_ENV PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/local/Cellar/cairo/1.10.2/lib/pkgconfig
make install
# pygobject
# introspection no worky:
curl -O
tar xf pygobject-2.28.6.tar.bz2 && cd pygobject-2.28.6
./configure --prefix=$VIRTUAL_ENV --disable-introspection
make install
# pygtk
curl -O
tar xf pygtk-2.24.0.tar.bz2 && cd pygtk-2.24.0
./configure --prefix=$VIRTUAL_ENV PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$VIRTUAL_ENV/lib/pkgconfig
make # moar coffee nao
make install
# There's a short test script you can run from the REPL here, if you want to
# verify that things are working:
# ~/bin/openxenmanager
source ~/.virtualenvs/pygtk/bin/activate
cd $HOME/src/python/openxenmanager

Is this still the approach you are recommending? Any changes in the last year?


ches commented Jul 30, 2012

I haven't tried, but it looks like nearly everything is in Homebrew now, so it should be a lot easier:

$ brew info pygtk
pygtk: stable 2.24.0
Depends on: glib, gtk+, pygobject, py2cairo
Not installed

==> Caveats
For non-Homebrew Python, you need to amend your PYTHONPATH like so:
  export PYTHONPATH=/usr/local/lib/python2.7/site-packages:$PYTHONPATH

So as long as you don't need strong virtualenv isolation (like testing different versions of these libs, installed into different virtualenvs), I'd have a go at brew install pygtk and see how it goes 😄

After doing
brew install pygtk and export PYTHONPATH=/usr/local/lib/python2.7/site-packages

I get

Traceback (most recent call last):
  File "", line 45, in <module>
    import gtk
ImportError: No module named gtk


I have the same issue :(. How can we take care of this?

File "" asks for python 2.5 and gtk 2.0

open and change the request line of python 2.5 to the version you have...
i have python 2.7 and it worked after that (i hade to change the permission of file and folder to do so ^_^)

brew no longer seems to have a formula for pygtx

[joule] ~ [1.9.3-p194] brew update
Updated Homebrew from 93fe0378 to ce39c3f3.
==> Updated Formulae
adobe-air-sdk  doxygen        zeromq
[joule] ~ [1.9.3-p194] brew info pygtx
Error: No available formula for pygtx 
[joule] ~ [1.9.3-p194] 

stuaxo commented Feb 21, 2014

@jedschneider - surely you want pygtk not pygtx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment