I wanted to run a python program on my Mac that was originally written for Linux. Should work just fine, right? Well, not quite. Given it took quite a while to figure out precisely what I needed, I’m writing it up for next time I need to do this.
The first problem was an error message triggered by the failure of
import gtk. The first assumption was that I needed to install
python-gtk2. Fortunately I’d already installed XCode. The easiest way to pull in packages for other code is to install some port software; I picked MacPorts. Installing that doesn’t take too long, and it sets up the right dependencies and environment variables. Then comes the fun stuff, installing the other packages. This takes some time, although being almost an automatic process makes it relatively easy.
The first thing to install was python_select, since I wanted to use a version of python other than the default 2.4, then the right version of python-gtk. For python 2.5, that meant
sudo port install python_select python_select python25 sudo port install py25-gtk2
The program still didn’t run, with the same gtk error message, so after vainly editing path variables etc, I looked at the source, and added
try: import pygtk pygtk.require("2.0") except: pass
try: import gtk
lines. This worked, and the program moved onto the next missing package.
Repeating for libxml2, and libxslt:
sudo port install py25-libxml2 sudo port install py25-libxslt
and my program finally worked.
Checking what was installed where is easy:
port contents package-name where package-name is the name of the package.
It looks like things work a lot better than they did just a few months ago, if all the articles I found on how to get libxml to work with python on the Mac are anything to go by.