简体   繁体   中英

error in compiling a cython .pyx file

I am totally new to cython and currently learning it.

I have a .pyx file and when I tried to compile it using the distutils module inside an ipython notebook, with the ff. 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:

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?

(The goal of this is that I should be able to import a .pyx file to ipython notebook.)

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'

Just posting so that others will have reference on these types of errors.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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