使用pyximport时如何设置Cython编译器标志? [英] How can I set Cython compiler flags when using pyximport?

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

问题描述

这个问题(使用distutils进行构建时,如何覆盖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编译器标志?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆