This question (How does one overwrite the default compile flags for Cython when building with distutils?) describes how to set default Cython flags when using distutils.
But how do I set default compile flags if I'm just using pyximport?
import pyximport
pyximport.install() # Pass compile flags here somehow?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With