Fortran 的扩展和带有 distutils 的库(.mod 未找到)

发布于 2025-01-13 00:06:39 字数 2419 浏览 1 评论 0原文

我开发了 Fortran 例程,并将其集成到我的 Python 代码中。因此,我将 numpy.distutils 与以下 setup.py 结合使用:

#!/usr/bin/env python
def configuration(parent_package='', top_path=None):
    from numpy.distutils.misc_util import Configuration
    config = Configuration('name', parent_package, top_path)
    src = ['dir1/dir2/a.f90']
    config.add_library('libname', sources=src,
                       extra_f90_compile_args=['-O3','-ffast-math','-funroll-loops'])
    config.add_extension(name='wrapper_name', sources=['dir1/dir2/wrapper_name.f90'],
                       extra_f90_compile_args=['-O3','-ffast-math','-funroll-loops'], l
                       libraries=['libname'])

    return config

if __name__ == "__main__":
    from numpy.distutils.core import setup
    setup(configuration=configuration)

setup.py 在我的 macOS 上运行良好,但在 Debian 上

Fortran f77 compiler: /usr/bin/gfortran -Wall -g -ffixed-form -fno-second-underscore -fPIC -O3 -funroll-loops
Fortran f90 compiler: /usr/bin/gfortran -Wall -g -fno-second-underscore -fPIC -O3 -funroll-loops
Fortran fix compiler: /usr/bin/gfortran -Wall -g -ffixed-form -fno-second-underscore -Wall -g -fno-second-underscore -fPIC -O3 -funroll-loops
compile options: '-Ibuild/src.linux-x86_64-3.7/build/src.linux-x86_64-3.7/dir1/dir2 -I/YYY/anaconda3/lib/python3.7/site-packages/numpy/core/include -Ibuild/src.linux-x86_64-3.7/numpy/distutils/include -I/YYY/anaconda3/include/python3.7m -c'
extra options: '-Jbuild/temp.linux-x86_64-3.7/dir1/dir2 -Ibuild/temp.linux-x86_64-3.7/dir1/dir2'
gfortran:f90: dir1/dir2/wrapper_name.f90
dir1/dir2/wrapper_name.f90:872:8:

     use a, only : RR
        1
Fatal Error: Can't open module file a.mod’ for reading at (1): Aucun fichier ou dossier de ce type
compilation terminated.
error: Command "/usr/bin/gfortran -Wall -g -fno-second-underscore -fPIC -O3 -funroll-loops -Ibuild/src.linux-x86_64-3.7/build/src.linux-x86_64-3.7/dir1/dir2 -I/YYY/anaconda3/lib/python3.7/site-packages/numpy/core/include -Ibuild/src.linux-x86_64-3.7/numpy/distutils/include -I/YYY/anaconda3/include/python3.7m -c -c dir1/dir2/wrapper_name.f90 -o build/temp.linux-x86_64-3.7/dir1/dir2/wrapper_name.o -Jbuild/temp.linux-x86_64-3.7/dir1/dir2 -Ibuild/temp.linux-x86_64-3.7/dir1/dir2" failed with exit status 1

运行不佳。 code>.mod 似乎不在正确的位置,但我不明白为什么它在 macOS 上工作而在 Debian 上不起作用。

I have developped Fortran's routines that I have integrated in my Python code. So I use numpy.distutils with the following setup.py:

#!/usr/bin/env python
def configuration(parent_package='', top_path=None):
    from numpy.distutils.misc_util import Configuration
    config = Configuration('name', parent_package, top_path)
    src = ['dir1/dir2/a.f90']
    config.add_library('libname', sources=src,
                       extra_f90_compile_args=['-O3','-ffast-math','-funroll-loops'])
    config.add_extension(name='wrapper_name', sources=['dir1/dir2/wrapper_name.f90'],
                       extra_f90_compile_args=['-O3','-ffast-math','-funroll-loops'], l
                       libraries=['libname'])

    return config

if __name__ == "__main__":
    from numpy.distutils.core import setup
    setup(configuration=configuration)

This setup.py works well on my macOS but not on Debian

Fortran f77 compiler: /usr/bin/gfortran -Wall -g -ffixed-form -fno-second-underscore -fPIC -O3 -funroll-loops
Fortran f90 compiler: /usr/bin/gfortran -Wall -g -fno-second-underscore -fPIC -O3 -funroll-loops
Fortran fix compiler: /usr/bin/gfortran -Wall -g -ffixed-form -fno-second-underscore -Wall -g -fno-second-underscore -fPIC -O3 -funroll-loops
compile options: '-Ibuild/src.linux-x86_64-3.7/build/src.linux-x86_64-3.7/dir1/dir2 -I/YYY/anaconda3/lib/python3.7/site-packages/numpy/core/include -Ibuild/src.linux-x86_64-3.7/numpy/distutils/include -I/YYY/anaconda3/include/python3.7m -c'
extra options: '-Jbuild/temp.linux-x86_64-3.7/dir1/dir2 -Ibuild/temp.linux-x86_64-3.7/dir1/dir2'
gfortran:f90: dir1/dir2/wrapper_name.f90
dir1/dir2/wrapper_name.f90:872:8:

     use a, only : RR
        1
Fatal Error: Can't open module file a.mod’ for reading at (1): Aucun fichier ou dossier de ce type
compilation terminated.
error: Command "/usr/bin/gfortran -Wall -g -fno-second-underscore -fPIC -O3 -funroll-loops -Ibuild/src.linux-x86_64-3.7/build/src.linux-x86_64-3.7/dir1/dir2 -I/YYY/anaconda3/lib/python3.7/site-packages/numpy/core/include -Ibuild/src.linux-x86_64-3.7/numpy/distutils/include -I/YYY/anaconda3/include/python3.7m -c -c dir1/dir2/wrapper_name.f90 -o build/temp.linux-x86_64-3.7/dir1/dir2/wrapper_name.o -Jbuild/temp.linux-x86_64-3.7/dir1/dir2 -Ibuild/temp.linux-x86_64-3.7/dir1/dir2" failed with exit status 1

The missing .mod seems to not be at the right place but I don't understand why it is working on macOS and not working in Debian.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文