Cython dynamic library problem

T

Tommy Grav

I am trying to learn how to use cython, and while I am following the
cython-dev
mailing list I didn't feel like this question was totally appropriate
for its audience
so I am trying here first.

I am on a max os x 10.5.4 running

drtgrav% python
ActivePython 2.5.2.2 (ActiveState Software Inc.) based on
Python 2.5.2 (r252:60911, Mar 27 2008, 17:40:23)
[GCC 4.0.1 (Apple Computer, Inc. build 5250)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
I have a pure python file that I am wanting to try to speed up some,
so I ran the file through cython, compiled it with gcc and tried to
call it from a python file
> cython integrations.pyx
> gcc -arch ppc -shared -c -fPIC -I/usr/include/python2.5
integration.c -o pyx_integration.so
> python integration_test.py
Traceback (most recent call last):
File "integration_test.py", line 1, in <module>
from astroPyX import pyx_integration
ImportError: dlopen(/Users/drtgrav/Work/myCode/Python/astroPyX/
pyx_integration.so, 2): no suitable image found. Did find:
/Users/drtgrav/Work/myCode/Python/astroPyX/pyx_integration.so: can't
map

where integration_test.py is

from astroPyX import pyx_integration

pyx_integration.test(0)
pyx_integration.test(100)

Does anyone know what the ImportError means and how to correct it?

Cheers
Tommy
 
B

bearophileHUGS

Rob Wolfe:
# setup.py
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext as build_pyx

setup(name = 'pyx_test',
ext_modules=[Extension('pyx_test', ['test_cython.pyx'])],
cmdclass = { 'build_ext': build_pyx })

$ python2.5 setup.py build_ext -i
running build_ext
cythoning test_cython.pyx to test_cython.c
building 'pyx_test' extension
creating build/temp.linux-i686-2.5
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.5 -c test_cython.c -o build/temp.linux-i686-2.5/test_cython.o
test_cython.c:86: warning: function declaration isn’t a prototype
test_cython.c:241: warning: function declaration isn’t a prototype
test_cython.c:59: warning: ‘__pyx_skip_dispatch’ defined but not used
gcc -pthread -shared -Wl,-O1 build/temp.linux-i686-2.5/test_cython.o -o pyx_test.so
$ python2.5 test_cython.py
0
100

With some intelligence added to Cython, probably there are ways to
reduce all this, and most of the times avoid any setup.py module too.

Bye,
bearophile
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top