Installing Python & PyGTK on Mac OsX

Recently i have been asked to develop an application that will work on Linux, and Mac os, so i started developing it on my Ubuntu, i chosed Python as the programming language and PyGTK as the GUI for it.

The application worked fine on my Ubuntu, but when i moved it to Mac OSx (Leopard), i had a problem importing the PyGTK module and the program GUI didn’t run. so i tried to install PyGTK from sources with all its dependencies, but after spending a day doing so i ended up with many errors in compiling the dependencies and finding them.

after some search i found out that i can do this using MacPorts.

so here is the steps i followed :

– Install X11 http://guide.macports.org/#installing.x11

– Install Xcode tools http://guide.macports.org/#installing.xcode

– Install MacPorts http://guide.macports.org/#installing.macports

– Make sure the paths are configured in your shell profile http://guide.macports.org/#installing.shell

– Restart your shell, and follow the next commands :

1- Install Python

sudo port -v install python25

2- Install Python select

sudo port -v install python_select

3- Activate our installed python version

sudo python_select python25

4- Install pygtk

sudo port -v install py25-gtk

5- Install some gnome themes and engines

sudo port -v install gnome-themes
sudo port -v install gtk-nodoka-engine
sudo port -v install gtk-smooth-engine
sudo port -v install gtk2-aurora
sudo port -v install gtk2-clearlooks
sudo port -v install gtk2-extra
sudo port -v install gtk2-industrial
sudo port -v install gtk2-murrine

6- Install theme switch

sudo port -v install gtk-theme-switch

7- Select which theme to be used by your applications by running the theme switch

switch2

Now you can have the applications you develop using python and pygtk running smoothly on mac os leopard.

20 thoughts on “Installing Python & PyGTK on Mac OsX

  1. Well, thank you so much. Wanting to try PyGtk on my brand new MacBook, I was afraid of having to compile so many packages by hand.

    One note though: be ready for several hours of compilation and a possible Xcode upgrade (3.1 required).

    Thanks once again,

  2. u r welcome David 🙂

    i have had the bad experience trying to compile each package, it was horrible, but macports saved me 🙂

  3. Thanks a lot!

    I searched for hours after I installed py-gtk2 instead of py25-gtk:

    >>> import pygtk

    "ImportError: No module named pygtk"

  4. Step one fails on Snow Leopard:

    (four or six traceback lines)

    ImportError: No module named _Res

    make[1]: *** [installmacsubtree] Error 1

    make: *** [frameworkinstallmaclib] Error 2

    Any clue on this?

  5. Compadre tu explicacion no sirve!!!!! mejor contestame en snow leopard hay q hacer algo similar o ya esta funcionando al 100%?

  6. Thank you!

    I could not get python_select to understand there was any other Python 2.5 than my apple-python25 even though I've installed Macports python25. Attempted using apple-python25 but failed misserably to build py25gtk.

    Everything worked out just fined when trying with python26 and py26gtk.

  7. Not sure if this is because I am getting Python 2.6 with 'port', but it failed to compile py26-gtk until I installed MacTeX.

  8. Your article in general is very helpful! I just want to add that for me python_select didn't
    work.

    sudo port select –set python python25

    made the current python version valid. In case it helps someone!

  9. FYI, the python_select package is no longer available. Some searches showed that you should now switch like this:
    sudo port select python python25

  10. I have installed py27-gtk on snow leopard. before doing this I upgraded Python 2.6.1 to 2.7.1. Now I am wondering whether any of gtk2 (installed as a dependency) variants has to be installed or not. The following is the information I got after I typed "port variants gtk2.

    " gtk2 has the variants:
    no_x11: Disable X11 support
    quartz: Support for native Mac OS X graphics
    * conflicts with x11
    * requires no_x11
    universal: Build for multiple architectures
    [+]x11: Enable rendering in X11
    * conflicts with quartz".
    thanks for any help.

  11. I have installed py27-gtk on snow leopard. before doing this I upgraded Python 2.6.1 to 2.7.1. Now I am wondering whether any of gtk2 (installed as a dependency) variants has to be installed or not. The following is the information I got after I typed "port variants gtk2"

    gtk2 has the variants:
    no_x11: Disable X11 support
    quartz: Support for native Mac OS X graphics
    * conflicts with x11
    * requires no_x11
    universal: Build for multiple architectures
    [+]x11: Enable rendering in X11
    * conflicts with quartz
    thank for any help.

  12. hello – I have been looking to get this pyGTK and MacPorts on my macbook Snow Leopard 10.6X (I am not technical) – because:
    1 pyGTK proofreading app by guiguts – python script and front end – The Python programs themselves can be downloaded here – http://git.sugarlabs.org/e-book-making-scripts/ma
    2 MacPorts to load ImageMagick (command line image manipulation)
    3 MacPorts to run PDFbeads (MRC compression of pdf to tiny size pdf)

    thankyou for this great great info.
    questions
    1) I understood python comes with 10.6X – how do I check what version I have? does your instructions need to be a certain version?

    2) instructions say
    "Download the latest MacPorts-1.x.x.dmg disk image (whose name does not contain -beta or -rc) from theMacPorts download directory."
    in the directory there are 2 options for 10.6X, which one do I choose?
    MacPorts-1.9.2-10.6-SnowLeopard.dmg
    MacPorts-1.9.2-10.6-SnowLeopard.dmg.asc

    3) I found HomeBrew – it helps non-techncial people install MacPorts
    must be installed to usr/local
    what do I type into terminal to see if I am in usr/local or change directory to this?
    https://github.com/mxcl/homebrew/wiki/installatio
    The default and recommended installation:
    ruby -e "$(curl -fsSL https://raw.github.com/gist/323731/39fc1416e34b9f
    Install Xcode.
    NOTE: (1) The order of the above steps doesn’t matter. (2) This method might not work for machines managed with Directory Services.

    4) do you think I best follow your macports instructions (as non-technical) or try this HomeBrew

    thankyou

  13. hello if I have homebrew installed – for people who go nutty trying to use macports (not technical people),

    do I I still need to install mac ports to get the pygtk?

  14. I went with py26-gtk, no idea if it worked yet because it takes HOURS AND HOURS AND HOURS AND HOURS AND HOURS AND HOURS AND HOURS AND HOURS AND HOURS!!!!!!!!!!

    Thanks though, I will just have to let my macbook sit here for a while, running all sort of useless flop tests. Let's just hope it works, I just needed it for 'meld' the directory diff program of which I don't even know if it is any good.

Leave a Reply

Your email address will not be published. Required fields are marked *