What I want to do this time is
ctypedef numpy.float64_t DOUBLE_t
I want to define it as.
To do this
You need to do cimport numpy
.
I want to do these two ctypedef
and cimport
.
The environment looks like this. OS X, Yosemite Cython 0.23.4 Python 3.4.3
Refer to the Cython 0.23.2 documentation: Building Cython code page and create the following two scripts.
test.pyx
import numpy
cimport numpy
ctypedef numpy.float64_t DOUBLE_t
setup.py
from distutils.core import setup
from Cython.Build import cythonize
setup(
name = 'test',
ext_modules = cythonize('test.pyx')
)
When I use this to run python setup.py build_ext --inplace
, I get the following error:
error.
sample.c:250:10: fatal error: 'numpy/arrayobject.h' file not found
#include "numpy/arrayobject.h"
^
1 error generated.
error: command 'clang' failed with exit status 1
I got an error saying that the file is missing. It seems that the path is different, so if you look at the site a little earlier, Something like this Cython 0.23.2 documentation: Compilation
Often, Python packages that offer a C-level API provide a way to find the necessary include files, e.g. for NumPy:
include_path = [numpy.get_include()]
It seemed to be common.
For the time being, let's put this in setup.py
.
setup.py
from distutils.core import setup
from Cython.Build import cythonize
import numpy
setup(
name = 'test',
ext_modules = cythonize('test.pyx')
include_path = [numpy.get_include()]
)
When I try to use this, I get an error again
error.
Unknown distribution option: 'include_path'
I was told that there is no such option.
Looking at stackoverflow and so on, it seems that everyone does not use ʻinclude_path, but uses ʻinclude_dirs
.
For the time being, try s / include_path / include_dirs
.
setup.py
from distutils.core import setup
from Cython.Build import cythonize
import numpy
setup(
name = 'test',
ext_modules = cythonize('test.pyx')
include_dirs = [numpy.get_include()]
)
When I tried it, it passed (o ・ ω ・ o) I don't know what it is, but it looks like it was done.
ʻInclude_dirs = [numpy.get_include ()] It sounds good to use. There are few new ones written in Japanese, so if you don't understand English, it can be painful. I compiled it this time, but there were a lot of warnings for ʻunused function
, so maybe I have to fix it? (Because it is an unused function, it may be left alone)
Recommended Posts