编译 cython .pyx 文件时出错
error in compiling a cython .pyx file
我是 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 文档,cython 代码必须与 python 代码不同地编译,为什么会这样?
(这样做的目的是我应该能够将 .pyx
文件导入 ipython 笔记本。)
我能够通过在设置中添加另一个参数 include_dirs=[numpy.get_include()])
来解决此问题,以解决未找到的文件错误 'numpy/arrayobject.h'
只是发布,以便其他人可以参考这些类型的错误。
我是 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 文档,cython 代码必须与 python 代码不同地编译,为什么会这样?
(这样做的目的是我应该能够将 .pyx
文件导入 ipython 笔记本。)
我能够通过在设置中添加另一个参数 include_dirs=[numpy.get_include()])
来解决此问题,以解决未找到的文件错误 'numpy/arrayobject.h'
只是发布,以便其他人可以参考这些类型的错误。