私はcythonを初めて使用しています。私は1つのソースコードファイルhello.pyx
ありますCythonチュートリアルのcpdefが機能しない
cdef extern from "math.h":
cpdef double sin(double x)
をして、私のsetup.py
ファイルは次のとおりです。その後、私は.so
にそれをコンパイル
from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize
ext_modules=[
Extension("hello",
sources=["hello.pyx"],
libraries=["m"] # Unix-like specific
)
]
setup(
name = "Demos",
ext_modules = cythonize(ext_modules)
)
。
しかし、私がimport hello
になったとき、私はhello.sin
の機能を持っていません。
"これはPythonコードのC sin()
関数への直接アクセスを提供するCythonモジュールです:"チュートリアルで書かれていますか?
外部宣言でofficial tutorialに従っています。 cythoningを実行するための
結果:
Compiling hello.pyx because it changed.
Cythonizing hello.pyx
running build_ext
building 'hello' extension
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall-Wstrict-prototypes -fPIC -I/pool/software/python/python27plus-ibm/include/python2.7 -c hello.c -o build/temp.linux-x86_64-2.7/hello.o
gcc -pthread -shared build/temp.linux-x86_64-2.7/hello.o -L/proj/dist/sandbox/miniconda/lib -lm -lpython2.7 -o /home/shaowu/Documents/cython_play/hello.so
モジュールはインポートされますが、そこには「sin」関数はありません。 'hello.sin'にアクセスしようとすると、あなたは' AttributeError'を取得しますか? –
@Jim Correct。私が 'dir(hello)'をするとき、 'sin 'はありません。理由はわかりません。 – Shaowu
私は使用しているバージョンをチェックします。私の印象は、これは数年前に追加されたので、おそらくあなたは古いです。 – DavidW