Trouble w/ distutils on OS X

The Problem: The default Python install on OS X (Panther) does not include all the necessary info to install some Python packages whose installers rely on distutils and the gcc compiler.

This will hopefully keep others from spending 2+ hours on the web looking for info… but it’s mostly for my own future reference. Full explanation and solution after the jump.

My Problem: I was trying to install the durus package on my Panther box at work. It uses the standard distutils way of installing things:

python setup.py install

But, it was throwing voluminous gcc errors, even when I did it as root. Now, the observant reader will note that I’d previously installed the Xcode (developer) tools on the box, as the gcc compiler was already there. The compile errors complained about not being able to find the “Python.h” file, which I later learned is a header file. I looked for them everywhere… they did not exist. Luckily, I found this guy’s website, which pointed me to look into SDK stuff.

At that point, I realized that while I had performed the “general” dev. tools install, there had to be more stuff that I hadn’t specifically installed. I popped the Xcode CD into the machine, and found the “DevSDK.pkg” installer in the “Packages” folder. Boink, installed. Hrm… still no header files to be found. Let’s try the “MaxOSX10.3.pkg”. Doink, installed.

Pt.1: Header Files!: Only then could I locate the Python header files. Mine were inside:
/Developer
 /SDKs
  /MacOSX10.3.0.sdk
   /System
    /Library
     /Frameworks
      /Python.framework
       /Headers/

An Oddity: I did find a “Headers” directory at:
/System
 /Library
  /Frameworks
   /Python.framework
    /Versions
     /Current
      /Headers/
… but that was merely a symlink pointing to “include/python2.3”… where no “include” subdirectory existed. So be careful.

Pt.2: Add Path! Going back to Mike Chambers’ advice, I went in and edited the durus package’s “setup.py” file, and added:

include_dirs = [path_to_headers],

… where path_to_headers was the full path (as a string) from root i.e., ‘/Developer/SDKs/Mac…’ etc. Note that the argument here is a Python list. If there is already an “include_dirs” argument in the setup.py file, then simply append your string to that list. Otherwise, create a new list with only that string as a member.

python setup.py install

Blickity-BLAM, no compiler or other errors. Just to be sure:

$ python
Python 2.3 (#1, Sep 13 2003, 00:49:11)
[GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import durus
>>>

No error = fuckin’ A.

Advertisements
Posted in Mac