How do you tell pyximport to use the cython --cplus option?
One way to make Cython create C++ files is to use a pyxbld file. For example, create foo.pyxbld
containing the following:
def make_ext(modname, pyxfilename):
from distutils.extension import Extension
return Extension(name=modname,
sources=[pyxfilename],
language='c++')
How can I set Cython compiler flags when using pyximport?
You should use a .pyxbld
file, see for example this question.
For a file named foo.pyx
, you would make a foo.pyxbld
file. The following would give extra optimization args:
def make_ext(modname, pyxfilename):
from distutils.extension import Extension
return Extension(name=modname,
sources=[pyxfilename],
extra_compile_args=['-O3', '-march=native'])
I think it might be possible to pass in extra setup options to pyximport.install
if you jump through enough hoops (messing around with distribute
) to get the setup_args in the form it likes, however in the pyximport
module documentation it recommends using a .pyxbld
file, and in the test code for pyximport
only that method is tested, so if there is another way it should be considered unstable/untested and .pyxbld
should be considered the proper way of doing this.
Compiling cython with gcc: No such file or directory from #include ios
<ios>
is a c++-header. The error message shows that you try to compile a C++-code as C-code.
Per default, Cython will produce a file with extension *.c
, which will be interpreted as C-code by the compiler later on.
Cython can also produce a file with the right file-extension for c++, i.e. *.cpp
. And there are multiple ways to trigger this behavior:
- adding
# distutils: language = c++
at the beginning of thepyx
-file. - adding
language="c++"
to theExtension
definition in thesetup.py
-file. - call
cython
with option--cplus
. - in IPython, calling
%%cython
magic with-+
, i.e.%%cython -+
. - for alternatives when building with
pyximport
, see this SO-question.
Actually, for cythonize
there is no command line option to trigger c++-generation, thus the first options looks like the best way to go:
# distutils: language = c++
from spacy.structs cimport TokenC
print("loading")
The problem is that spacy/structs.pxd
uses c++-constructs, for example vectors or anything else cimported from libcpp
:
...
from libcpp.vector cimport vector
...
and thus also c++-libraries/headers are needed for the build.
Wrt. Anaconda Python 3.4 and Cython
import numpy
is just a regular import. Unless you do cimport numpy
Cython doesn't treat this specially (it doesn't import headers or other compile-time files), thus there's nothing special to include.
I very much doubt there is any special feature Anaconda is doing.
If you want to configure pyximport
, you can make a pxybld
file, such as when you want to support C++ with pyximport
.
Error with Object mapper reading JSON from file
"firstName" != "firstname"
Check the case of your property.
Related Topics
How to Enforce the 'Override' Keyword
Is Casting Std::Pair<T1, T2> Const& to Std::Pair<T1 Const, T2> Const& Safe
Equivalent of "Using Namespace X" for Scoped Enumerations
Does Copy List Initialization Invoke Copy Ctor Conceptually
Is Maximum_Wait_Objects Really 64
Can Void* Be Used to Store Function Pointers
Cmake - Global Linker Flag Setting (For All Targets in Directory)
C++11 Range Based Loop: How Does It Really Work
Strange Behavior of Const_Cast
Why Is the Copy Constructor Called When We Pass an Object as an Argument by Value to a Method
Erasing Vector::End from Vector
C++ Templates: Conditionally Enabled Member Function
When to Use C++ Private Inheritance Over Composition