2017-06-21 6 views
0

同様の質問は何度も何度も尋ねられてきましたが、残念ながらNumpyでCythonを使用する際に問題が発生しました。`cimport numpy`のあるCythonは失敗します

私が構築しよう
# file test.pyx 
import numpy as np 
#cimport numpy as np 

def func(): 
    print("hello") 

:この最小限の例を(ほとんどhere例は以下のもの)乗り

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)、I非コメントまでcimport ...ライン

fatal error: numpy/arrayobject.h: No such file or directory

np.get_include()によって返されたパスがを持っているん:、その後私はよく知っているエラーが発生しますヘッダが、実行されます実際g++コマンドに含まれるDIRは-I/...として欠落しています。

g++-7 -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/usr/local/include -I/usr/local/opt/openssl/include -I/usr/local/opt/sqlite/include -I/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/include/python3.6m -c test.c -o build/temp.macosx-10.11-x86_64-3.6/test.o

この問題が発生する可能性がありますどのような任意のアイデアを?

Mac OSでPython 3.6.1、pip3でインストールされているすべて(Cython、Numpy、..)、Cython 0.25.2を使用しています。代わりに、単純なcythonizeコマンドの

+0

あなたが試すことができ: 'ext_modules = cythonize((拡張子( "テスト"、 ソースは= [ "test.pyx"]、 include_dirs = [np.get_include()]、 )、 ))' –

+0

も、cythonのバージョンは何ですか? 'cython3 --version' –

+0

ピエール、それは魔法です!それは動作しますが、私はなぜ/どのように(まだ) – Bart

答えて

2

ext_modules = cythonize((Extension("test", sources=["test.pyx"], include_dirs=[np.get_include()],),)) 

を使用include_dirsオプションは、代わりに「cythonize」とinclude_pathを使用しての「拡張」するためにここに与えられています。

関連する問題