Showing posts with label arrays. Show all posts
Showing posts with label arrays. Show all posts

Sunday, June 10, 2012

header file location for numpy arrays (cython)

Today was the first time I tried working with numpy arrays in Cython. I got a compilation error saying that the header file for numpy could not be found. Here I found an easy fix for this problem. The setup.py script can be changed to automatically detect and add the numpy include path:


from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
import numpy

ext_modules = [Extension("xx_cython",["xx_cython.pyx"],\
    libraries=["m"],include_dirs=[numpy.get_include()])]

setup(
    name= 'xx model class',
    cmdclass = {'build_ext': build_ext},
    ext_modules = ext_modules
)