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
Leave a Reply

avatar
20 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
16 Comment authors
MosselmanlightpurelightHariBrian Recent comment authors
  Subscribe  
Notify of
David
Guest
David

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,

Asyclalay
Guest

Hello!
How do you look for information for your blog content?

Dominic
Guest
Dominic

Thanks a lot!

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

>>> import pygtk

"ImportError: No module named pygtk"

John D
Guest
John D

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?

dilip
Guest
dilip

import pygtk fails ? any suggestions ? help would be great

ZaFhieL
Guest
ZaFhieL

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

Xiao
Guest

Thanks! nice article, was getting tired of how bland gtk looked on mac

kalle
Guest
kalle

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.

Xiao
Guest

Would you know how to make the theme switch work for su as well? If I open a GTK app using sudo, it goes back to the original theme

Ryan
Guest
Ryan

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.

Wey
Guest
Wey

How to add .profiles ?

Warning: No index(es) found! Have you synced your source indexes?

Error: Port python25 not found

Thx

Olga
Guest
Olga

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!

Brian
Guest
Brian

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

Hari
Guest
Hari

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.

Hari
Guest
Hari

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.

purelight
Guest
purelight

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… Read more »

light
Guest
light

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?

Mosselman
Guest
Mosselman

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.