gpt4 book ai didi

python - cimport 给出 fatal error : 'numpy/arrayobject.h' file not found

转载 作者:太空狗 更新时间:2023-10-30 01:54:44 32 4
gpt4 key购买 nike

我正在尝试自学 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.

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

最佳答案

好的,上面已经指出了,之前也有人问过类似的问题。例如:Make distutils look for numpy header files in the correct place .我通过使用带有以下行的设置文件使我的代码正常工作

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,所以我不确定是否需要另一个修复程序。

关于python - cimport 给出 fatal error : 'numpy/arrayobject.h' file not found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20333128/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com