[英]cimport gives fatal error: 'numpy/arrayobject.h' file not found
I'm trying to teach myself Cython but having problems accessing numpy. 我正在尝试自学Cython,但是在访问numpy时遇到了问题。 The problems seem to be when I use 'cimport'. 问题似乎出在我使用“ cimport”时。 For example when importing the following function: 例如,导入以下功能时:
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
I get error: 我得到错误:
/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.
Any simple instructions on how to resolve this would be much appreciated! 任何有关如何解决此问题的简单说明将不胜感激!
Ok, as has been pointed out above, similar questions have been asked before. 好的,正如上面已经指出的,以前也曾提出过类似的问题。 Eg: Make distutils look for numpy header files in the correct place . 例如: 让distutils在正确的位置查找numpy头文件 。 I got my code to work by using a setup file with the line 我通过在该行中使用安装文件来使代码工作
include_dirs = [np.get_include()],
As in: 如:
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
)
I haven't yet tried using pyximport so I'm not sure whether another fix is required for that. 我还没有尝试使用pyximport,所以不确定是否需要其他修复程序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.