简体   繁体   English

编译cython .pyx文件时出错

[英]error in compiling a cython .pyx file

I am totally new to cython and currently learning it. 我对cython完全陌生,目前正在学习。

I have a .pyx file and when I tried to compile it using the distutils module inside an ipython notebook, with the ff. 我有一个.pyx文件,当我尝试使用ff在ipython笔记本中使用distutils模块进行编译时。 code: 码:

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
)

I got the following error: 我收到以下错误:

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

And when I tried to compile it in another way using python setup.py build_ext --inplace with the same code stored in setup.py I get this error: 当我尝试使用python setup.py build_ext --inplacesetup.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

How might the compilation be resolved? 如何解决该汇编?

Another question, according to cython documentation, cython codes must be compiled unlike with the python codes, why is this so? 根据cython文档,还有一个问题,与python代码不同,必须编译cython代码,为什么会这样呢?

(The goal of this is that I should be able to import a .pyx file to ipython notebook.) (这样做的目的是我应该能够将.pyx文件导入ipython笔记本。)

I was able to fix this by adding another parameter include_dirs=[numpy.get_include()]) in setup to address the unfound file error 'numpy/arrayobject.h' 我可以通过在安装程序中添加另一个参数include_dirs=[numpy.get_include()])来解决此问题,以解决未找到的文件错误'numpy/arrayobject.h'

Just posting so that others will have reference on these types of errors. 只是发布,以便其他人可以参考这些类型的错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM