【问题标题】:cimport gives fatal error: 'numpy/arrayobject.h' file not foundcimport 给出致命错误:找不到“numpy/arrayobject.h”文件
【发布时间】:2013-12-02 16:33:07
【问题描述】:

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

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

【问题讨论】:

标签: python numpy cython


【解决方案1】:

好的,正如上面所指出的,之前已经提出过类似的问题。 例如: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,所以我不确定是否需要其他修复。

【讨论】:

  • 似乎在最新的 distutils include_dirs 被忽略(至少在 OSX 上)
猜你喜欢
  • 2016-12-31
  • 2021-02-14
  • 2017-12-06
  • 2015-12-14
  • 2013-01-17
  • 1970-01-01
  • 2020-10-02
  • 2015-01-20
相关资源
最近更新 更多