【问题标题】:error in compiling a cython .pyx file编译 cython .pyx 文件时出错
【发布时间】:2015-07-29 15:44:45
【问题描述】:

我对 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 notebook。)

【问题讨论】:

    标签: python compilation cython ipython-notebook


    【解决方案1】:

    我可以通过在设置中添加另一个参数 include_dirs=[numpy.get_include()]) 来解决此问题,以解决未找到的文件错误 'numpy/arrayobject.h'

    只是发布,以便其他人可以参考这些类型的错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-13
      • 2018-11-10
      • 2023-04-06
      • 2013-10-04
      • 1970-01-01
      相关资源
      最近更新 更多