Skip to content Skip to sidebar Skip to footer

How Can I Set Cython Compiler Flags When Using Pyximport?

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 d

Solution 1:

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:

defmake_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.

Post a Comment for "How Can I Set Cython Compiler Flags When Using Pyximport?"