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

 三千仇人-奈我何 发布于 2023-02-13 13:32

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

任何关于如何解决这个问题的简单说明将非常感谢!

1 个回答
  • 好的,正如上面已经指出的那样,之前已经提出了类似的问题.例如:让distutils在正确的位置查找numpy头文件.我通过使用带有该行的设置文件使我的代码工作

    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,所以我不确定是否需要另外修复.

    2023-02-13 13:33 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有