Skip to main content
 首页 » 编程设计

python之使用 Python 3 导入 f2py 模块时 undefined symbol

2024年10月25日16lexus

我正在尝试使用 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 

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

请您参考如下方法:

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