在我的安裝中,numpy的arrayobject.h
位於…/site-packages/numpy/core/include/numpy/arrayobject.h
。我寫了一個使用numpy的一個簡單的用Cython腳本:讓distutils在正確的位置尋找numpy頭文件
cimport numpy as np
def say_hello_to(name):
print("Hello %s!" % name)
我也有以下的distutils setup.py
(從Cython user guide複製):
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
ext_modules = [Extension("hello", ["hello.pyx"])]
setup(
name = 'Hello world app',
cmdclass = {'build_ext': build_ext},
ext_modules = ext_modules
)
當我嘗試建立與python setup.py build_ext --inplace
,用Cython試圖做如下:
gcc -fno-strict-aliasing -Wno-long-double -no-cpp-precomp -mno-fused-madd \
-fno-common -dynamic -DNDEBUG -g -Os -Wall -Wstrict-prototypes -DMACOSX \
-I/usr/include/ffi -DENABLE_DTRACE -arch i386 -arch ppc -pipe \
-I/System/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5 \
-c hello.c -o build/temp.macosx-10.5-i386-2.5/hello.o
可以預見,這沒有找到arrayobject.h
。我怎樣才能讓distutils使用numpy包含文件的正確位置(而不是讓用戶定義$ CFLAGS)?
我在ipython筆記本中使用'%% cython'魔法時遇到同樣的問題..我想知道是否有一個簡單的解決方案 – pbreach 2014-09-14 06:26:32
對於任何人看這個作爲非'numpy'相關工作,'numpy.get_include'的定義是[here](https://github.com/numpy/numpy/blob/56678fe56dce97871bb49febf0b2c0206541eada/numpy/lib/utils.py#L18)。 – 2015-07-07 04:30:19
我不得不在「Extension」調用中移動「include_dirs」行,以使其與cython 0.24一起工作 – 2016-06-08 19:19:21