如何使用 fortran 扩展构建 Python 包

Tit*_*ego 5 python dll fortran python-wheel

我制作了一个包含 fortran 扩展的 Python 包。当我运行pip install -e .在本地测试它时,它可以工作,但是当我构建轮子并将它们上传到 PyPI 时,然后pip install my_package这就是我导入它时得到的结果:

ImportError: DLL load failed while importing functions: The specified module could not be found.
Run Code Online (Sandbox Code Playgroud)

看起来setup.py像这样:

ImportError: DLL load failed while importing functions: The specified module could not be found.
Run Code Online (Sandbox Code Playgroud)

工作流程如下所示:

from numpy.distutils.core import Extension, setup
...
extension = Extension(name='my_package.fortran.functions',
                          sources=['my_package/fortran/erf.f', 'my_package/fortran/erf.pyf'],
                          extra_link_args=["-static", "-static-libgfortran", "-static-libgcc"],)
                          #extra_compile_args=['/d2FH4-'] if sys.platform == 'win32' else [])

setup(
...
ext_modules=[extension]
...
)
Run Code Online (Sandbox Code Playgroud)

我在使用 ubuntu 和 macos 时遇到问题,因此对这些操作系统进行了评论,但我也想为这些操作系统构建。

安装依赖项正在尝试解决此问题。

我只为 CPython 构建,因为 Pypy 带来了问题。

delvewheel 被评论是因为出现了这个错误:

FileNotFoundError: Unable to find library: liberf.qnh5sc52t4pc5446h2dbxzj22hkv2erk.gfortran-win32.dll
Run Code Online (Sandbox Code Playgroud)

如何避免 dll 出现第一个错误?

如何使用适用于所有平台的编译代码构建 python 包?

这是物有所值的套餐