f2py 编译失败:无法识别 python27.dll 文件格式

1 投票
1 回答
1845 浏览
提问于 2025-04-18 07:20

我有一些Fortran代码需要通过Python来运行。作为第一步,我正在尝试一个简单的子程序:

  subroutine multiply(a,b,n,c)
    double precision, intent(in) :: a(n), b(n)
    integer, intent(in) :: n
    double precision(out) :: c(n)
    integer :: i
    do i=1,n
     c(i)=a(i)*b(i)
    end do  
  end subroutine multiply

然后我试着用f2py.py来编译它:

f2py -c --fcompiler=gnu95 --compiler=mingw32 -m foo mult.f

但是在寻找python27.dll时出现了一个错误:文件格式无法识别。以下是编译器的输出:

C:\Users\Richard\Documents\Code\fortran>f2py -c --fcompiler=gnu95 --compiler=mingw32 -m foo mult.f
 running build
running config_cc
unifing config_cc, config, build_clib, build_ext, build commands --compiler options
running config_fc
unifing config_fc, config, build_clib, build_ext, build commands --fcompiler options
running build_src
build_src
building extension "foo" sources
f2py options: []
f2py:> c:\users\richard\appdata\local\temp\tmpxwldfw\src.win-amd64-2.7\foomodule.c
creating c:\users\richard\appdata\local\temp\tmpxwldfw
creating c:\users\richard\appdata\local\temp\tmpxwldfw\src.win-amd64-2.7
Reading fortran codes...
        Reading file 'mult.f' (format:fix,strict)
Post-processing...
        Block: foo
                        Block: multiply
Post-processing (stage 2)...
Building modules...
        Building module "foo"...
                Constructing wrapper function "multiply"...
                  multiply(a,b,c,[n])
        Wrote C/API module "foo" to file "c:\users\richard\appdata\local\temp\tmpxwldfw\src.win-amd64-2.7\foomodule.c"
  adding 'c:\users\richard\appdata\local\temp\tmpxwldfw\src.win-amd64-2.7\fortranobject.c' to sources.
  adding 'c:\users\richard\appdata\local\temp\tmpxwldfw\src.win-amd64-2.7' to include_dirs.
copying C:\Users\Richard\AppData\Local\Enthought\Canopy\User\lib\site-packages\numpy\f2py\src\fortranobject.c -> c:\users\richard\appdata\local\temp\tmpxwldfw\src.win-amd64-2.7
copying C:\Users\Richard\AppData\Local\Enthought\Canopy\User\lib\site-packages\numpy\f2py\src\fortranobject.h -> c:\users\richard\appdata\local\temp\tmpxwldfw\src.win-amd64-2.7
build_src: building npy-pkg config files
running build_ext
Looking for python27.dll
Building import library (arch=AMD64): "C:\Users\Richard\AppData\Local\Enthought\Canopy\User\libs\libpython27.a" (from C:\Users\Richard\AppData\Local\Enthought\Canopy\User\python27.dll)
**objdump.exe: C:\Users\Richard\AppData\Local\Enthought\Canopy\User\python27.dll: File format not recognized**
Traceback (most recent call last):
  File "C:\Users\Richard\AppData\Local\Enthought\Canopy\User\Scripts\f2py-script.py", line 24, in <module> main()

 ..removed details of stack trace, finally ending with

File "C:\Users\Richard\AppData\Local\Enthought\Canopy\User\lib\site-packages\numpy\distutils\mingw32ccompiler.py", line 399, in _build_import_library_amd64    generate_def(dll_file, def_file)
File "C:\Users\Richard\AppData\Local\Enthought\Canopy\User\lib\site-packages\numpy\distutils\mingw32ccompiler.py", line 278, in generate_def    raise ValueError("Symbol table not found")
ValueError: Symbol table not found

我真的不确定是什么导致了这个问题。任何建议都将非常感谢。

1 个回答

0

这个错误和这里提到的“方法3”是一样的。可以看看原作者在那里的解决方案。

在Windows 10上用f2py和Python 3.6编译Fortran模块

撰写回答