Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cython compilation error with include_path as a keyword in cythonize

Tags:

python

cython

I have a code snippet, called 'test.pyx':

import numpy as np
cimport numpy as np

print(np.arange(10))

And then I wrote two setup.py to compile them. The first one worked fine:

from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize
import numpy as np

extensions = [
    Extension('test', ['test.pyx'], include_dirs = [np.get_include()]),
    ]

setup(
    ext_modules = cythonize(extensions)
    )

And this one did not work (which is also from an example on http://docs.cython.org/src/reference/compilation.html):

from distutils.core import setup
from Cython.Build import cythonize
import numpy as np


setup(
    ext_modules = cythonize('./test.pyx', include_path=[np.get_include()])
    )

It says: ./test.c(346) : fatal error C1083: Cannot open include file: 'numpy/arrayobject.h': No such file or directory.

I am using Python 3.3 64-bit on Windows 64-bit, with WinSDK 7.1.

like image 985
Yuxiang Wang Avatar asked May 25 '14 16:05

Yuxiang Wang


People also ask

What C compiler does cython use?

Linux The GNU C Compiler (gcc) is usually present, or easily available through the package system. On Ubuntu or Debian, for instance, it is part of the build-essential package. Next to a C compiler, Cython requires the Python header files.

What is Cimport cython?

The cimport statement is used in a definition or implementation file to gain access to names declared in another definition file. Its syntax exactly parallels that of the normal Python import statement. When pure python syntax is used, the same effect can be done by importing from special cython.


1 Answers

This is a Cython documentation bug, see also https://github.com/cython/cython/issues/1480

like image 121
Jeroen Demeyer Avatar answered Oct 04 '22 09:10

Jeroen Demeyer