我需要通过python运行一些fortran代码。作为第一步,我尝试了一个简单的子程序:
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
我真的不确定导致这种情况的原因。任何建议都将不胜感激。
答案 0 :(得分:0)
错误与此处提到的“方法3”相同。在此处查看OP的解决方案
Compile fortran module with f2py and Python 3.6 on Windows 10