简体   繁体   English

cimport给出致命错误:找不到“ numpy / arrayobject.h”文件

[英]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.

相关问题 致命错误:numpy/arrayobject.h:google colab 中没有这样的文件或目录#include“numpy/arrayobject.h” - fatal error: numpy/arrayobject.h: No such file or directory #include "numpy/arrayobject.h" in google colab Cython:致命错误:未找到“numpy/arrayobject.h”文件,使用 numpy - Cython: fatal error: 'numpy/arrayobject.h' file not found, using numpy Cython:“致命错误:numpy/arrayobject.h:没有这样的文件或目录” - Cython: "fatal error: numpy/arrayobject.h: No such file or directory" 致命错误:numpy / arrayobject.h:没有这样的文件或目录 - fatal error: numpy/arrayobject.h: No such file or directory 致命错误:使用 pyenv 时找不到“arrayobject.h”文件 - fatal error: 'arrayobject.h' file not found when using pyenv 如何解决这个致命错误:numpy/arrayobject.h:没有这样的文件或目录? - How do I resolve this make fatal error: numpy/arrayobject.h: No such file or directory? 编译.pyx文件时缺少numpy / arrayobject.h - Missing numpy/arrayobject.h while compiling .pyx file 相当于使用#include <Numeric/arrayobject.h> 在Numpy - equivalent of using #include <Numeric/arrayobject.h> in Numpy 在编译swig输出时找不到arrayobject.h - arrayobject.h not found while compiling swig output 将 numpy 的 arrayobject.h 包含到 bitbake 配方中 - 如何修复安装顺序? - Include numpy's arrayobject.h into bitbake recipe - how to fix installation order?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM