使用 Pythran 模块分发 Python 应用程序时,您可以:
将模块声明为常规 Python 模块。毕竟,它们 100% 兼容 Python。
将它们声明为 PythranExtension 并且 Pythran 将编译它们:
从 distutils.core 导入设置
需要这两行才能在 setup.py 中使用 pythran 导入 setuptools setuptools.dist.Distribution(dict(setup_requires='pythran'))
from pythran.dist import PythranExtension, PythranBuildExt setup(..., ext_modules=[PythranExtension("mymodule", ["mymodule.py"])], cmdclass={"build_ext": PythranBuildExt}) PythranBuildExt 是可选的,但必须使用不同的 C++ 编译器构建扩展。它默认派生自 distuil 的 build_ext,但您可以改用 PythranBuildExt[base_cls] 来更改其基类。
.pythranrc 中支持的所有配置选项也可以通过可选的配置参数以列表的形式传递,例如 config=['compiler.blas=openblas']
来自 pythran doc.https://pythran.readthedocs.io/en/latest/MANUAL.html