我对cython完全不熟悉并且正在学习它。
我有一个.pyx文件,当我尝试使用ff的ipython笔记本中的distutils模块编译它。代码:
from distutils.core import setup
from Cython.Build import cythonize
setup(
name = "functions_cython",
ext_modules = cythonize('../utils/cython_func.pyx'), # accepts a glob pattern
)
我收到以下错误:
An exception has occurred, use %tb to see the full traceback.
SystemExit: usage: __main__.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
or: __main__.py --help [cmd1 cmd2 ...]
or: __main__.py --help-commands
or: __main__.py cmd --help
error: option -f not recognized
当我尝试使用python setup.py build_ext --inplace
以setup.py
中存储的相同代码以另一种方式编译它时,我收到此错误:
build_ext --inplace
Compiling cython_func.pyx because it changed.
Cythonizing cython_func.pyx
running build_ext
building 'utils.cython_func' extension
creating build
creating build/temp.macosx-10.10-x86_64-2.7
clang -fno-strict-aliasing -fno-common -dynamic -I/usr/local/include -I/usr/local/opt/sqlite/include -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c cython_func.c -o build/temp.macosx-10.10-x86_64-2.7/cython_func.o
cython_func.c:239:10: fatal error: 'numpy/arrayobject.h' file not found
#include "numpy/arrayobject.h"
^
1 error generated.
error: command 'clang' failed with exit status 1
如何解决编译?
另一个问题,根据cython文档,cython代码必须编译,与python代码不同,为什么会这样?
(这样做的目的是我应该能够将.pyx
文件导入ipython笔记本。)
答案 0 :(得分:2)
我能够通过在设置中添加另一个参数include_dirs=[numpy.get_include()])
来解决此问题,以解决不合适的文件错误'numpy/arrayobject.h'
只需发布,以便其他人可以参考这些类型的错误。