我对cython非常陌生,目前正在学习它。
我有一个.pyx文件,当我试图使用ipython笔记本中的distutils模块和ff编译它时。代码:
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文档,与python代码不同的是,必须编译cython代码,为什么会这样?
(这样做的目的是我应该能够将一个.pyx文件导入到IPython记事本。)
发布于 2015-07-30 09:12:08
我能够通过在安装程序中添加另一个参数include_dirs=[numpy.get_include()])来解决未找到的文件错误'numpy/arrayobject.h'来修复这个问题。
只是张贴,以便其他人可以参考这些类型的错误。
https://stackoverflow.com/questions/31705178
复制相似问题