python 中的 fortran 子例程导入失败

fortran subroutine import in python fails

我正在尝试将 Fortran 子例程导入 python 代码。按照本指南 https://notmatthancock.github.io/2017/02/10/calling-fortran-from-python.html 我在我的 Fortran 代码中添加了以下行:

!f2py intent(in) :: ear,ne,parames,ifl
!f2py intent(out) photar,photer

然而,当我尝试使用 f2py -c fireball_ES_param.f -m fireball 创建 fireball.so 以导入我的 python 代码时,我收到数百条警告,这可能是问题所在,但我不确定: https://www.4shared.com/s/f2ynHZ_Wjda (太长了,发在这里)。

在任何情况下,都会创建 fireball.cpython-34m.so 文件,但是当我尝试从 python 导入该文件时,我得到:

$ python

Python 2.7.6 (default, Nov 13 2018, 12:45:42)  [GCC 4.8.4] on
linux2 Type "help", "copyright", "credits" or "license" for more
information.
>>> import fireball Traceback (most recent call last):
File "<stdin>", line 1, in <module> ImportError:
  No module named fireball

我试过了:

import sys

sys.path.append('/path/to/folder/containing/fireball.cpython-34m.so')

但得到了相同的结果。我不确定创建 fireball.so 或其 import.

是否存在问题

f2py 链接到 Python 3.4(因此 fireball.cpython-34m.so 中的 34)但 python3 实际上是 3.6 版(见最后评论)。

您的选择:

  • 使用 Python 3.4 启动您的程序,它应该作为 python3.4
  • 可用
  • 将 f2py 更新为 Python 3.6。如果你通过 pip 安装,pip install --user -U numpy 应该可以。然后重建扩展。