我是 Python 新手,希望能够使用我现有的 Fortran 代码并从 Python 运行它。我正在尝试按照在线说明使用 F2PY 编译一个小的“Hello world”Fortran 程序。
我在 Windows 上工作。到目前为止,我已经安装了 Python 2.7.3、NumPy 1.6.1、SciPy 10.1 和 MinGW 4.8。
然后我尝试了(除其他外)
f2py.py -c --compiler=mingw32 --fcompiler=gnu95 -m foo foo.f90
这会报告无效的版本号。
ValueError:无效的版本号“4”。
如果有人能建议出了什么问题以及我需要改变什么才能让它运行,我将不胜感激。F2PY 的完整输出如下:
D:\python\fortran2>f2py.py -c --compiler=mingw32 --fcompiler=gnu95 -m foo foo.f90
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:\docume~1\ajr\locals~1\temp\tmpwvnr2c\src.win32-2.7\foomodule.c
creating c:\docume~1\ajr\locals~1\temp\tmpwvnr2c
creating c:\docume~1\ajr\locals~1\temp\tmpwvnr2c\src.win32-2.7
Reading fortran codes...
Reading file 'foo.f90' (format:free)
Post-processing...
Block: foo
Block: hello
Post-processing (stage 2)...
Building modules...
Building module "foo"...
Constructing wrapper function "hello"...
hello()
Wrote C/API module "foo" to file "c:\docume~1\ajr\locals~1\temp\tmpwvnr2c\src.win32-2.7\foomodule.c"
adding 'c:\docume~1\ajr\locals~1\temp\tmpwvnr2c\src.win32-2.7\fortranobject.c' to sources.
adding 'c:\docume~1\ajr\locals~1\temp\tmpwvnr2c\src.win32-2.7' to include_dirs.
copying C:\Python27\lib\site-packages\numpy\f2py\src\fortranobject.c -> c:\docume~1\ajr\locals~1\temp\tmpwvnr2c\src.win32-2.7
copying C:\Python27\lib\site-packages\numpy\f2py\src\fortranobject.h -> c:\docume~1\ajr\locals~1\temp\tmpwvnr2c\src.win32-2.7
build_src: building npy-pkg config files
running build_ext
Traceback (most recent call last):
File "c:\python27\scripts\f2py.py", line 24, in <module>
main()
File "C:\Python27\lib\site-packages\numpy\f2py\f2py2e.py", line 588, in main
run_compile()
File "C:\Python27\lib\site-packages\numpy\f2py\f2py2e.py", line 574, in run_compile
setup(ext_modules = [ext])
File "C:\Python27\lib\site-packages\numpy\distutils\core.py", line 186, in setup
return old_setup(**new_attr)
File "C:\Python27\lib\distutils\core.py", line 152, in setup
dist.run_commands()
File "C:\Python27\lib\distutils\dist.py", line 953, in run_commands
self.run_command(cmd)
File "C:\Python27\lib\distutils\dist.py", line 972, in run_command
cmd_obj.run()
File "C:\Python27\lib\site-packages\numpy\distutils\command\build.py", line 37, in run
old_build.run(self)
File "C:\Python27\lib\distutils\command\build.py", line 127, in run
self.run_command(cmd_name)
File "C:\Python27\lib\distutils\cmd.py", line 326, in run_command
self.distribution.run_command(command)
File "C:\Python27\lib\distutils\dist.py", line 972, in run_command
cmd_obj.run()
File "C:\Python27\lib\site-packages\numpy\distutils\command\build_ext.py", line 92, in run
force=self.force)
File "C:\Python27\lib\site-packages\numpy\distutils\ccompiler.py", line 556, in new_compiler
compiler = klass(None, dry_run, force)
File "C:\Python27\lib\site-packages\numpy\distutils\mingw32ccompiler.py", line 127, in __init__
elif self.gcc_version < "4.":
File "C:\Python27\lib\distutils\version.py", line 138, in __cmp__
other = StrictVersion(other)
File "C:\Python27\lib\distutils\version.py", line 40, in __init__
self.parse(vstring)
File "C:\Python27\lib\distutils\version.py", line 107, in parse
raise ValueError, "invalid version number '%s'" % vstring
ValueError: invalid version number '4.'