Python cimport给出了致命错误:';numpy/arrayobject.h';找不到文件

Python cimport给出了致命错误:';numpy/arrayobject.h';找不到文件,python,numpy,cython,Python,Numpy,Cython,我试着自学Cython,但在使用numpy时遇到了问题。问题似乎是当我使用“cimport”时。 例如,在导入以下函数时: cimport numpy def cy_sum(x): cdef numpy.ndarray[int, ndim=1] arr = x cdef int i, s = 0 for i in range(arr.shape[0]): s += arr[i] return s 我得到一个错误: /Users/Dan

我试着自学Cython,但在使用numpy时遇到了问题。问题似乎是当我使用“cimport”时。 例如,在导入以下函数时:

cimport numpy
def cy_sum(x):
    cdef numpy.ndarray[int, ndim=1] arr = x 
    cdef int i, s = 0
    for i in range(arr.shape[0]):
            s += arr[i] 
    return s
我得到一个错误:

/Users/Daniel/.pyxbld/temp.macosx-10.6-x86_64-2.7/pyrex/test.c:314:10: fatal error: 'numpy/arrayobject.h' file not found

include "numpy/arrayobject.h"

1 error generated.

任何关于如何解决此问题的简单说明都将不胜感激

好的,如上所述,以前也有人问过类似的问题。 例:。 我通过使用一个带有行的设置文件使代码正常工作

include_dirs = [np.get_include()], 
例如:

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

ext  =  [Extension( "cy_test", sources=["cy_test.pyx"] )]

setup(
   name = "testing", 
   cmdclass={'build_ext' : build_ext}, 
   include_dirs = [np.get_include()],   
   ext_modules=ext
   )

我还没有尝试使用pyximport,所以我不确定是否需要另一个修复程序

--应该能帮你解决这个问题。基本上,您只需要帮助将
C
编译器指向
numpy
头文件。这是否回答了您的问题?在最新的distutils
include\u dirs
中,它似乎被忽略(至少在OSX上)