Cython: "fatal error: numpy/arrayobject.h: No such file or directory"
In your setup.py
, the Extension
should have the argument include_dirs=[numpy.get_include()]
.
Also, you are missing np.import_array()
in your code.
--
Example setup.py:
from distutils.core import setup, Extensionfrom Cython.Build import cythonizeimport numpysetup( ext_modules=[ Extension("my_module", ["my_module.c"], include_dirs=[numpy.get_include()]), ],)# Or, if you use cythonize() to make the ext_modules list,# include_dirs can be passed to setup()setup( ext_modules=cythonize("my_module.pyx"), include_dirs=[numpy.get_include()])
For a one-file project like yours, another alternative is to use pyximport
. You don't need to create a setup.py
... you don't need to even open a command line if you use IPython ... it's all very convenient. In your case, try running these commands in IPython or in a normal Python script:
import numpyimport pyximportpyximport.install(setup_args={"script_args":["--compiler=mingw32"], "include_dirs":numpy.get_include()}, reload_support=True)import my_pyx_moduleprint my_pyx_module.some_function(...)...
You may need to edit the compiler of course. This makes import and reload work the same for .pyx
files as they work for .py
files.
The error means that a numpy header file isn't being found during compilation.
Try doing export CFLAGS=-I/usr/lib/python2.7/site-packages/numpy/core/include/
, and then compiling. This is a problem with a few different packages. There's a bug filed in ArchLinux for the same issue: https://bugs.archlinux.org/task/22326