[Pyrex] Linking with python standard lib...

Brian Myers tarkawebfoot at charter.net
Mon Dec 11 01:03:37 UTC 2006


Hi all,

I've got my decimal library working (at least initially) now. I was  
looking through it and found some places to enhance performance with  
calls to the python api. I made changes and got things compiling, but  
then when I called the python api functions, I got a symbol not found  
error. I was pretty sure that was because I wasn't linking to the  
standard python library. So I updated my setup.py file and rebuilt.

The problem for me was that I'm working on OS/X and I've installed  
python through DarwinPorts. Doing so means the standard python  
library is in an unusual place. It's in /opt/local/lib. I came up  
with the following setup.py file to link the right library:

from distutils.core import setup
from distutils.extension import Extension
from Pyrex.Distutils import build_ext
import os.path
import sys
decNumber = os.path.join('_decNumber', 'decNumber.c')
decContext = os.path.join('_decNumber', 'decContext.c')
setup(name="py_decNumber",
       version="0.1",
       ext_modules=[Extension("decimals",
                     ["decimals.pyx", decNumber, decContext],
                     include_dirs=['_decNumber'],
                     library_dirs=[os.path.join(sys.exec_prefix,  
'lib')],
                     libraries=['python' + sys.version[:3]])],
       cmdclass = {'build_ext': build_ext}
     )

This builds just fine, but when I try to import the module I get:

 >>> from py_decNumber import decimals
Traceback (most recent call last):
   File "<stdin>", line 1, in ?
SystemError: Objects/moduleobject.c:48: bad argument to internal  
function

I've never seen this message before. Unfortunately, I'm somewhat new  
to python under Unix and OS/X especially. Anyone know what's going on  
here? Any suggestions about the best way to find the standard python  
library in the install script?

Thanx

Brian




More information about the Pyrex mailing list