简体   繁体   English

f2py与Hello World

[英]f2py with hello world

I am trying to learn how to compile fortran code in python using f2py. 我正在尝试学习如何使用f2py在python中编译fortran代码。 I am using Python 2.7.10 (via Python (x,y)) and Mingw32 as my compiler. 我正在使用Python 2.7.10(通过Python(x,y))和Mingw32作为编译器。 I am trying to get this to work in 64-bit Windows 7, but the Python 2.7.10 is running in 32-bit. 我正在尝试使其在64位Windows 7中运行,但Python 2.7.10在32位运行。 I added the appropriate paths for C:\\MingW\\bin\\ and the C:\\Python27\\ to my system's PATH file. 我在系统的PATH文件中添加了C:\\MingW\\bin\\C:\\Python27\\的适当路径。

When I trying to compile a simple hello.f "Hello, World!" 当我尝试编译一个简单的hello.f“ Hello,World!” program, I get the following errors: 程序,出现以下错误:

C:\Users\Tim\Desktop>f2py -c -m hello hello.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 "hello" sources
f2py options: []
f2py:> c:\users\tim~1.rue\appdata\local\temp\tmpriisfr\src.win32-2.7\hellomodule.c
creating c:\users\tim~1.rue\appdata\local\temp\tmpriisfr\src.win32-2.7
Reading fortran codes...
    Reading file 'hello.f' (format:fix,strict)
Post-processing...
    Block: hello
            Block: hello
Post-processing (stage 2)...
Building modules...
    Building module "hello"...
    Wrote C/API module "hello" to file "c:\users\tim~1.rue\appdata\local\temp\tmpriisfr\src.win32-2.7\hellomodule.c"
  adding 'c:\users\tim~1.rue\appdata\local\temp\tmpriisfr\src.win32-2.7\fortranobject.c' to sources.
  adding 'c:\users\tim~1.rue\appdata\local\temp\tmpriisfr\src.win32-2.7' to include_dirs.
copying C:\Python27\lib\site-packages\numpy\f2py\src\fortranobject.c -> c:\users\tim~1.rue\appdata\local\temp\tmpriisfr\src.win32-2.7
copying C:\Python27\lib\site-packages\numpy\f2py\src\fortranobject.h -> c:\users\tim~1.rue\appdata\local\temp\tmpriisfr\src.win32-2.7
build_src: building npy-pkg config files
running build_ext
Cannot build msvcr library: "msvcr90d.dll" not found
customize Mingw32CCompiler
customize Mingw32CCompiler using build_ext
customize GnuFCompiler
Could not locate executable g77
Could not locate executable f77
customize IntelVisualFCompiler
Could not locate executable ifort
Could not locate executable ifl
customize AbsoftFCompiler
Could not locate executable f90
customize CompaqVisualFCompiler
Could not locate executable DF
customize IntelItaniumVisualFCompiler
Could not locate executable efl
customize Gnu95FCompiler
Found executable C:\MinGW\bin\gfortran.exe
Found executable C:\MinGW\bin\gfortran.exe
customize Gnu95FCompiler
customize Gnu95FCompiler using build_ext
building 'hello' extension
compiling C sources
C compiler: gcc -O2 -Wall -Wstrict-prototypes

creating c:\users\tim~1.rue\appdata\local\temp\tmpriisfr\Release
creating c:\users\tim~1.rue\appdata\local\temp\tmpriisfr\Release\users
creating c:\users\tim~1.rue\appdata\local\temp\tmpriisfr\Release\users\tim~1.rue
creating c:\users\tim~1.rue\appdata\local\temp\tmpriisfr\Release\users\tim~1.rue\appdata
creating c:\users\tim~1.rue\appdata\local\temp\tmpriisfr\Release\users\tim~1.rue\appdata\local
creating c:\users\tim~1.rue\appdata\local\temp\tmpriisfr\Release\users\tim~1.rue\appdata\local\temp
creating c:\users\tim~1.rue\appdata\local\temp\tmpriisfr\Release\users\tim~1.rue\appdata\local\temp\tmpriisfr
creating c:\users\tim~1.rue\appdata\local\temp\tmpriisfr\Release\users\tim~1.rue\appdata\local\temp\tmpriisfr\src.win32-2.7
compile options: '-DNPY_MINGW_USE_CUSTOM_MSVCR -D__MSVCRT_VERSION__=0x0900 -Ic:\users\tim~1.rue\appdata\local\temp\tmpriisfr\src.win32-2.7 -IC:\Python27\lib\site-packages\numpy\core\include -IC:\Python27\include -IC:\Python27\PC -c'
gcc -O2 -Wall -Wstrict-prototypes -DNPY_MINGW_USE_CUSTOM_MSVCR -D__MSVCRT_VERSION__=0x0900 -Ic:\users\tim~1.rue\appdata\local\temp\tmpriisfr\src.win32-2.7 -IC:\Python27\lib\site-packages\numpy\core\include -IC:\Python27\include -IC:\Python27\PC -c c:\users\tim~1.rue\appdata\local\temp\tmpriisfr\src.win32-2.7\hellomodule.c -o c:\users\tim~1.rue\appdata\local\temp\tmpriisfr\Release\users\tim~1.rue\appdata\local\temp\tmpriisfr\src.win32-2.7\hellomodule.o
Found executable C:\MinGW\bin\gcc.exe
gcc -O2 -Wall -Wstrict-prototypes -DNPY_MINGW_USE_CUSTOM_MSVCR -D__MSVCRT_VERSION__=0x0900 -Ic:\users\tim~1.rue\appdata\local\temp\tmpriisfr\src.win32-2.7 -IC:\Python27\lib\site-packages\numpy\core\include -IC:\Python27\include -IC:\Python27\PC -c c:\users\tim~1.rue\appdata\local\temp\tmpriisfr\src.win32-2.7\fortranobject.c -o c:\users\tim~1.rue\appdata\local\temp\tmpriisfr\Release\users\tim~1.rue\appdata\local\temp\tmpriisfr\src.win32-2.7\fortranobject.o
compiling Fortran sources
Fortran f77 compiler: C:\MinGW\bin\gfortran.exe -Wall -g -ffixed-form -fno-second-underscore -O3 -funroll-loops
Fortran f90 compiler: C:\MinGW\bin\gfortran.exe -Wall -g -fno-second-underscore -O3 -funroll-loops
Fortran fix compiler: C:\MinGW\bin\gfortran.exe -Wall -g -ffixed-form -fno-second-underscore -Wall -g -fno-second-underscore -O3 -funroll-loops
compile options: '-Ic:\users\tim~1.rue\appdata\local\temp\tmpriisfr\src.win32-2.7 -IC:\Python27\lib\site-packages\numpy\core\include -IC:\Python27\include -IC:\Python27\PC -c'
gfortran.exe:f77: hello.f
C:\MinGW\bin\gfortran.exe -Wall -g -Wall -g -shared c:\users\tim~1.rue\appdata\local\temp\tmpriisfr\Release\users\tim~1.rue\appdata\local\temp\tmpriisfr\src.win32-2.7\hellomodule.o c:\users\tim~1.rue\appdata\local\temp\tmpriisfr\Release\users\tim~1.rue\appdata\local\temp\tmpriisfr\src.win32-2.7\fortranobject.o c:\users\tim~1.rue\appdata\local\temp\tmpriisfr\Release\hello.o -Lc:\mingw\lib\gcc\mingw32\4.8.1 -LC:\Python27\libs -LC:\Python27\PCbuild -lpython27 -lgfortran -o .\hello.pyd
C:\Python27\libs/libpython27.a: error adding symbols: File format not recognized
collect2.exe: error: ld returned 1 exit status
error: Command "C:\MinGW\bin\gfortran.exe -Wall -g -Wall -g -shared c:\users\tim~1.rue\appdata\local\temp\tmpriisfr\Release\users\tim~1.rue\appdata\local\temp\tmpriisfr\src.win32-2.7\hellomodule.o c:\users\tim~1.rue\appdata\local\temp\tmpriisfr\Release\users\tim~1.rue\appdata\local\temp\tmpriisfr\src.win32-2.7\fortranobject.o c:\users\tim~1.rue\appdata\local\temp\tmpriisfr\Release\hello.o -Lc:\mingw\lib\gcc\mingw32\4.8.1 -LC:\Python27\libs -LC:\Python27\PCbuild -lpython27 -lgfortran -o .\hello.pyd" failed with exit status 1

Can someone help me sort out why this isn't compiling and help me to get this working? 有人可以帮我弄清楚为什么它不编译并帮助我使它正常工作吗?

Actually this seems to be a bug in Python 2.7.10 , with 32bit libpython27.a containing 64-bit objects. 实际上,这似乎是Python 2.7.10中的错误 ,因为32位libpython27.a包含64位对象。 To fix it, either downgrade python to 2.7.9, or upgrade it to 2.7.11 (or you can follow the route from this question, but depending on your experience this could be painful). 要解决问题,请将python降级至2.7.9,或将其升级至2.7.11(或者您可以按照问题进行操作,但是根据您的经验,可能会很痛苦)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM