Wednesday, March 2, 2011

Building PyGTK for Mac

In the past couple of months a number of people have asked me to provide new native Mac PyGTK builds. I do not use PyGTK anymore, so I don't have time to maintain these builds - sorry. Out of curiosity I recently built PyGTK on my Snow Leopard (10.6.6) machine, just to see if the process has gotten any easier, and I must say that it has. I was able to build the entire thing without any hacking. So, to those of you asking me to provide new builds, here you have a complete HOWTO of how to build a native Mac PyGTK:

  1. Create a new user account (to make sure that no MacPorts/Fink/other libraries are available in the environment)

  2. Install git (http://code.google.com/p/git-osx-installer/downloads/list?can=3)

  3. Log in to the new account (I ssh'ed in from a Terminal)

  4. Download the build script (https://github.com/jralls/gtk-osx-build/raw/master/gtk-osx-build-setup.sh)

  5. Add ~/.local/bin to PATH

  6. Edit ~/.jhbuildrc-custom setting setup_sdk like so: setup_sdk(target="10.6", sdk_version="10.6", architectures=["i386"])

  7. Run these build commands:

    1. $ jhbuild bootstrap

    2. $ jhbuild build meta-gtk-osx-bootstrap

    3. $ jhbuild build meta-gtk-osx-core

    4. $ jhbuild build pygtk



  8. Download the PyGTK hello world script (http://www.pygtk.org/pygtk2tutorial/examples/helloworld.py)

  9. Update your PYTHONPATH: export export PYTHONPATH=$PYTHONPATH:~/gtk/inst/lib/python2.6/site-packages

  10. Make sure that 32-bit Python is used: export VERSIONER_PYTHON_PREFER_32_BIT=yes

  11. Test your build by running the hello world script: python helloworld.py


Note that to perform the last step you need to be properly logged in (not just through SSH).

I hope that this helps some of the people that have asked me about PyGTK builds. Happy hacking ;-)

1 comment:

  1. I had to use: jhbuild bootstrap --ignore-system because I kept getting the following:

    *** Error during phase configure of gtk+: ########## Error running autoreconf -fis && ./configure --prefix /Users/smu/gtk/inst --libdir '/Users/smu/gtk/inst/lib' --with-gdktarget=quartz --disable-static *** [10/18]

    [1] Rerun phase configure
    [2] Ignore error and continue to build
    [3] Give up on module
    [4] Start shell
    [5] Reload configuration
    [6] Go to phase "wipe directory and start over"
    [7] Go to phase "clean"
    [8] Go to phase "distclean"
    choice:

    ReplyDelete