类似的问题已经问了很多很多次了,但不幸的是,我再次遇到了在Numpy中使用Cython的问题。以这个最小的例子为例(它与示例这里大致相同):
# file test.pyx
import numpy as np
#cimport numpy as np
def func():
print("hello")我试着用:
from distutils.core import setup
from Cython.Build import cythonize
import numpy as np
import os
os.environ["CC"] = "g++-7"
setup(
ext_modules = cythonize("test.pyx", include_path = [np.get_include()])
)这个示例(python setup.py build_ext --inplace)起作用,直到我取消注释cimport ...行,然后我得到了一个众所周知的错误:
致命错误: numpy/arrayobject.h:没有这样的文件或目录
np.get_include()返回的路径确实有arrayobject.h头,但在执行的实际g++命令中,包含dir作为-I/...缺少。
g++-7 -Wno-未使用-结果-比较-代码-fno-共同的-dynamic -DNDEBUG -g -fwrapv -O3 -Wall -W严格-原型-i/usr/local/local/opt/openssl/include-i/usr/local/sqlite/include -c test.c -o构建/tem.macosx-10.11-x86_64-3.6/test.o
知道是什么导致了这个问题吗?
我在Mac上使用Python3.6.1 (Cython,Numpy,.)安装了pip3和Cython0.25.2。
发布于 2017-06-21 16:35:07
而不是简单的cythonize命令,请使用
ext_modules = cythonize((Extension("test", sources=["test.pyx"], include_dirs=[np.get_include()], ), ))include_dirs选项在这里给出了“扩展”,而不是使用带有"cythonize“的include_path。
发布于 2018-11-06 16:14:53
我的解决办法:
os.environ["C_INCLUDE_PATH"] = np.get_include()
setup(
ext_modules = cythonize("test.pyx")
)https://stackoverflow.com/questions/44680042
复制相似问题