本文介绍了使用pyximport时如何设置Cython编译器标志?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

这个问题()介绍了使用distutils时如何设置默认Cython标志。

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.

但是如果我只是使用pyximport,如何设置默认编译标志?

But how do I set default compile flags if I'm just using pyximport?

import pyximport
pyximport.install()  # Pass compile flags here somehow?


推荐答案

您应该使用。 pyxbld 文件,例如,参见。
对于名为 foo.pyx 的文件,您将创建一个 foo.pyxbld 文件。以下将给出额外的优化参数:

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'])

我认为,如果有可能将额外的设置选项传递给 pyximport.install 您会跳过足够多的箍(与 distribute 交谈)来获得喜欢的形式的setup_args,但是在 pyximport 模块文档,建议使用 .pyxbld 文件,并且在 pyximport 的测试代码中,仅测试该方法,因此,如果有另一种方法,应将其视为不稳定/未试用,并应将视为执行此操作的正确方法。

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.

这篇关于使用pyximport时如何设置Cython编译器标志?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 16:50