[Pythonmac-SIG] Extending Python (OS 10.3.9)

Chris Barker Chris.Barker at noaa.gov
Fri Sep 30 21:36:40 CEST 2005


The best advice I can give you is to use distutils to do the compiling 
for you. It knows about all the include and linking directories that are 
required:

http://docs.python.org/dist/dist.html

If your case is simple, which it seems to be so far, you can write a 
very simple setup.py script, and build with:

python setup.py build.

As a bonus, you can use the same setup.py to build on other platforms.

Here is a simple example:

#!/usr/bin/env python2.3

from distutils.core import setup, Extension

setup (name = "MyModule",
        version = "1.0",
        ext_modules = [Extension('MyModule',sources=['MyModule.c'])]
)


This will build the C file: MyModule.c into an extension library MyModule.so

One other suggestion:
http://www.cosc.canterbury.ac.nz/~greg/python/Pyrex/

Look into using pyrex instead of dealing with all that raw C.

Or, if you are working with a C or C++ library, look into SWIG or 
Boost::python

-Chris









-- 
Christopher Barker, Ph.D.
Oceanographer
                                     		
NOAA/OR&R/HAZMAT         (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov


More information about the Pythonmac-SIG mailing list