Aug 202009
 

I wanted to run a python pro­gram on my Mac that was ori­gin­ally writ­ten for Linux. Should work just fine, right? Well, not quite. Giv­en it took quite a while to fig­ure out pre­cisely what I needed, I’m writ­ing it up for next time I need to do this.

The first prob­lem was an error mes­sage triggered by the fail­ure of import gtk. The first assump­tion was that I needed to install python-gtk2. For­tu­nately I’d already installed XCode. The easi­est way to pull in pack­ages for oth­er code is to install some port soft­ware; I picked Mac­Ports. Installing that does­n’t take too long, and it sets up the right depend­en­cies and envir­on­ment vari­ables. Then comes the fun stuff, installing the oth­er pack­ages. This takes some time, although being almost an auto­mat­ic pro­cess makes it rel­at­ively easy.

The first thing to install was python_select, since I wanted to use a ver­sion of python oth­er than the default 2.4, then the right ver­sion of python-gtk. For python 2.5, that meant

sudo port install python_select
python_select python25
sudo port install py25-gtk2

The pro­gram still did­n’t run, with the same gtk error mes­sage, so after vainly edit­ing path vari­ables etc, I looked at the source, and added 

try:
      import pygtk
      pygtk.require("2.0")
except:
      pass

before the

try:
      import gtk

lines. This worked, and the pro­gram moved onto the next miss­ing package.

Repeat­ing for libxml2, and libxslt:

sudo port install py25-libxml2
sudo port install py25-libxslt

and my pro­gram finally worked.

Check­ing what was installed where is easy: port contents package-name where pack­age-name is the name of the package. 

It looks like things work a lot bet­ter than they did just a few months ago, if all the art­icles I found on how to get libxml to work with python on the Mac are any­thing to go by. 

  2 Responses to “Python and the Mac”

  1. If you need a Syn­aptic-like fron­tend for installing ports I sug­gest to take a look at Por­ti­c­us (http://porticus.alittledrop.com/)

    HTH

  2. […] hap­pens when a Ruby­ist’s spouse starts slip­ping into Python? http://www.laurenwood.org/anyway/2009/08/20/python-and-the-mac/ […]

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)

/* ]]> */