building an extension module with autotools?

Gerhard Häring gh at ghaering.de
Wed Dec 3 16:41:48 EST 2008


Michael George wrote:
> Hello,
> 
> (Please CC me in replies, as I am off-list)

Ok, but please reply publicly.

> I'm building an application (a game) in python, with a single C module 
> containing some performance-critical code.  I'm trying to figure out the 
> best way to set it up to build. 

Use distutils and keep your sanity.

> Distutils seems to be designed only for 
> building and distributing code that lives in site-packages.  I'd prefer 
> not to install it in the global site-packages, but rather group all of 
> the files together.

Then just use the build step of distutils and do the rest from your 
build script (Python-based, make based, whatever you prefer).

> I've tried using automake, 

In my opinion, this is serious overkill. automake is good for making 
stuff work on a herd of different Unixen with various combinations of 
libc functions available etc. But for developing a Python extension, it 
doesn't help much at all. All you need to know about Python is available 
via macros if you import Python.h.

> however I'm worried about libtool not getting 
> the options right while building my module.  It seems to me like the 
> ideal frankenstein monster would be for automake to invoke distutils to 
> do the actual building.  However I'm relatively new to both autotools 
> and distutils, so getting this rigged up has been a bit of a challenge.  
> Can anybody point me to a good example of something like this or give me 
> any pointers?

My recommendation is to start simple instead of wasting too much time 
upfront for probably nothing.

Here's what I'd start with:

#!/bin/sh
python setup.py build
cp build/lib.*/*.so .
python test.py

HTH

-- Gerhard



More information about the Python-list mailing list