-2

工具步骤.py

def HelloWord():
    print('hello word')

测试pythran.py

from calaTools.toolsTep import *
#pythran export callOtherPyFiles()
def callOtherPyFiles():
    HelloWord()

编译pythran testpythran.py

  • 关键
    我有麻烦了。您的输入文件似乎与 Pythran 的约束不匹配...
  • 测试pythran.py:

    无:无错误:找不到模块“calaTools.toolsTep”。

当保存文件中有两个函数并且可以找到时,在不同的文件中会发生这些错误

4

1 回答 1

0

使用 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

于 2021-08-16T01:04:40.770 回答