Dear Cython users,
After more than 12 hours of fighting with Cython+distutils, I am getting quite frustrated. I am trying to do something that seems like it should be quite trivial - compile a pure Python file with an augmenting PXD file backpack using Cython+distutils. I have taken the pure-Python files listed below from
Stefan's talk, and I cannot for the life of me build a setup.py that will compile properly and - this is the part I can't get to work - include the typedefs from the PXD. If I can get this to work, I should be able to manage everything else for my modules.
I have the two files integrate_py.py and integrate_py.pxd in the same directory, and when I run python setup.py build_ext --inplace, python builds example.pyd, but doesn't include the PXD typdefs in the c-code it generates. Can someone point me to my mistake? I feel like this is a pretty common use-case of pure Python mode with Cython, and it would be great to have this better documented - I would be happy to contribute in this regards. Other users seem to have run into the same problems before:
http://codespeak.net/pipermail/cython-dev/2009-September/006837.html
For what it's worth, if at a command prompt in the source folder I do cython.py -a example_py.py, it builds the example.c properly (including the typedefs from the PXD file). Any thoughts.
Thanks again,
Ian
#### integrate_py.py ###########
# integrate_py.py
from math import sin
def f(x):
return sin(x**2)
def integrate_f(a, b, N):
dx = (b-a)/N
s = 0
for i in range(N):
s += f(a+i*dx)
return s * dx
#### integrate_py.pxd ########
# integrate_py.pxd
cimport cython
cpdef double f(double x)
@cython.locals(dx=double, s=double, i=int)
cpdef integrate_f(double a, double b, int N)
#### setup.py ##############
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
ext_modules = [Extension("example", ["integrate_py.py"])]
setup(
cmdclass = {'build_ext': build_ext},
ext_modules = ext_modules
)