Cython:致命错误:使用numpy找不到'numpy / arrayobject.h'文件

时间:2016-08-24 03:51:52

标签: python numpy cython cythonize

我正在尝试将我的Ipython笔记本代码移动到python。但我有错误

fatal error: 'numpy/arrayobject.h' file not found
#include "numpy/arrayobject.h"

,即使我在设置中包含了numpy

我的setup.py:

from distutils.core import setup, Extension
from Cython.Build import cythonize
import numpy

setup(
    ext_modules=cythonize("Trajectory.pyx"),
    include_dirs=[numpy.get_include()]
)

Trajectory.pyx文件

cimport numpy as np
import  numpy as np 

我在osX上运行,Python 2.7.10

它还会在错误发生之前向我提供此信息,希望这有助于确定问题: clang -fno-strict-aliasing -fno-common -dynamic -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -I / Applications / Xcode.app /目录/开发人员/平台/ MacOSX.platform / Developer / SDKs / MacOSX10.11.sdk / System / Library / Frameworks / Tk.framework / Versions / 8.5 / Headers -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes - 我/ usr / local / include -I / usr / local / opt / openssl / include -I / usr / local / opt / sqlite / include -I / usr / local / Cellar / python / 2.7.10_2 / Frameworks / Python。 framework / Versions / 2.7 / include / python2.7 -c Trajectory.c -o build / temp.macosx-10.11-x86_64-2.7 / Trajectory.o

当我跑步时

import numpy
numpy.get_include()

我明白了:

'/usr/local/lib/python2.7/site-packages/numpy/core/include'

我查看目录,/ numpy /arrayobject.h就在那里。所以我真的不知道为什么它说没有这样的文件

1 个答案:

答案 0 :(得分:2)

FWIW,我在macOS(Python 3.7.6,Cython 0.29.14,macOS 10.15)上遇到了相同的问题('numpy/arrayobject.h' file not found)。

这是我用来正确包含路径的解决方法:

from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize
import numpy

setup(name='Foo',
      ext_modules=cythonize([Extension("bar", ["bar.pyx"], include_dirs=[numpy.get_include()])])
)