【问题标题】:Undefined symbol when importing f2py module, using Python 3使用 Python 3 导入 f2py 模块时未定义的符号
【发布时间】:2015-03-16 15:23:55
【问题描述】:

我正在尝试使用 f2py 编译一个最小的 Fortran90 子例程,以与 Python 3 一起使用。当我使用 Python 2.7 时它可以工作,但是当将它导入 Python 3 文件时,我收到一条错误消息。我需要它在 Python 3 中工作。

我的 Fortran 子程序:

subroutine test(a,b)
    implicit none

    integer, intent(in) :: a
    integer, intent(out) :: b

    b = a*2
end subroutine

这就是我的编译方式:

f2py -c test.f90 -m test 

然后我尝试像这样在 Python 3 中导入

import test

并得到这个错误:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: /home/.../hello.so: undefined symbol: PyCObject_Type

我已经搜索过这个错误,但没有发现任何对我有意义的东西。

【问题讨论】:

  • 您确实下载并安装了 Python 3 版本的模块,是吗?
  • 据我了解,numpy 自带 f2py。我检查了 Python3 中的 Numpy 版本,它是 1.9.2 版本。我应该安装不同版本的 f2py 吗?
  • 可能只是您在命令行上选择了错误的版本。检查which f2py 或类似的。
  • 我确实使用了错误的版本。我现在用 f2py3 编译,现在它可以工作了。非常感谢。

标签: python python-3.x fortran fortran90 f2py


【解决方案1】:

正如@cdarke 所指出的,我使用了错误版本的 f2py。用 f2py3.4 编译解决了这个问题。

【讨论】:

    猜你喜欢
    • 2021-07-23
    • 2015-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-23
    • 1970-01-01
    相关资源
    最近更新 更多