Similar questions have been asked many, many times, but unfortunately I have yet again ran into a problem with using Cython with Numpy. Take this minimal example (which pretty much follows the examples here):
# file test.pyx
import numpy as np
#cimport numpy as np
def func():
print("hello")
Which I try to build with:
from distutils.core import setup
from Cython.Build import cythonize
import numpy as np
import os
os.environ["CC"] = "g++-7"
setup(
ext_modules = cythonize("test.pyx", include_path = [np.get_include()])
)
This example works (python setup.py build_ext --inplace), until I un-comment the cimport ... line, after which I get the well know error:
fatal error: numpy/arrayobject.h: No such file or directory
The path returned by np.get_include() does have the arrayobject.h header, but in the actual g++ command that gets executed, the include dir is missing as a -I/...:
g++-7 -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/usr/local/include -I/usr/local/opt/openssl/include -I/usr/local/opt/sqlite/include -I/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/include/python3.6m -c test.c -o build/temp.macosx-10.11-x86_64-3.6/test.o
Any idea what might cause this problem?
I'm using Python 3.6.1 on Mac OS, everything (Cython, Numpy, ..) installed with pip3, and Cython 0.25.2.
ext_modules = cythonize((Extension("test", sources=["test.pyx"], include_dirs=[np.get_include()], ), ))cython3 --version