f2py using MS tools when MinGW installed ...

882 views
Skip to first unread message

Brendan

unread,
Dec 28, 2009, 7:42:05 AM12/28/09
to python(x,y)
Hi there,

I have Python(x,y) 2.6.2.0 installed with MinGW. I wanted to write a
FORTRAN subroutine to speed up my code a little.

Using the f2py command appears to detect the gfortran.exe that comes
with the Python(x,y) MinGW install but insists on vcvarsall.bat be
installed (something that comes with Visual Studio C++) I installed VS
C++ 2008 Express and this went away but now it appears f2py wants to
use the MS linker which does not work it seems ...

C:\Users\brendan\Desktop\PhD\Results\2009\Tl2201 Fermi Surface Fitting
\Python>f2
py.py -c -m inrng inrng.f
running build
running config_cc
unifing config_cc, config, build_clib, build_ext, build commands --
compiler opti
ons
running config_fc
unifing config_fc, config, build_clib, build_ext, build commands --
fcompiler opt
ions
running build_src
building extension "inrng" sources
f2py options: []
f2py:> c:\users\brendan\appdata\local\temp\tmp2sabar
\src.win32-2.6\inrngmodule.c

creating c:\users\brendan\appdata\local\temp\tmp2sabar
creating c:\users\brendan\appdata\local\temp\tmp2sabar\src.win32-2.6
Reading fortran codes...
Reading file 'inrng.f' (format:fix,strict)
Post-processing...
Block: inrng
Block: inrng
Post-processing (stage 2)...
Building modules...
Building module "inrng"...
Constructing wrapper function "inrng"...
ids = inrng(msh,smsh,rng,[lmsh,lsmsh])
Wrote C/API module "inrng" to file "c:\users\brendan\appdata
\local\temp\
tmp2sabar\src.win32-2.6/inrngmodule.c"
adding 'c:\users\brendan\appdata\local\temp\tmp2sabar
\src.win32-2.6\fortranobj
ect.c' to sources.
adding 'c:\users\brendan\appdata\local\temp\tmp2sabar\src.win32-2.6'
to includ
e_dirs.
copying C:\Python26\lib\site-packages\numpy\f2py\src\fortranobject.c -
> c:\users
\brendan\appdata\local\temp\tmp2sabar\src.win32-2.6
copying C:\Python26\lib\site-packages\numpy\f2py\src\fortranobject.h -
> c:\users
\brendan\appdata\local\temp\tmp2sabar\src.win32-2.6
running build_ext
No module named msvccompiler in numpy.distutils; trying from distutils
customize MSVCCompiler
customize MSVCCompiler using build_ext
customize GnuFCompiler
Could not locate executable g77
Could not locate executable f77
customize IntelVisualFCompiler
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:\Program Files\pythonxy\mingw\bin\gfortran.exe
Found executable C:\Program Files\pythonxy\mingw\bin\gfortran.exe
customize Gnu95FCompiler
customize Gnu95FCompiler using build_ext
building 'inrng' extension
compiling C sources
creating c:\users\brendan\appdata\local\temp\tmp2sabar\Release
creating c:\users\brendan\appdata\local\temp\tmp2sabar\Release\users
creating c:\users\brendan\appdata\local\temp\tmp2sabar\Release\users
\brendan
creating c:\users\brendan\appdata\local\temp\tmp2sabar\Release\users
\brendan\app
data
creating c:\users\brendan\appdata\local\temp\tmp2sabar\Release\users
\brendan\app
data\local
creating c:\users\brendan\appdata\local\temp\tmp2sabar\Release\users
\brendan\app
data\local\temp
creating c:\users\brendan\appdata\local\temp\tmp2sabar\Release\users
\brendan\app
data\local\temp\tmp2sabar
creating c:\users\brendan\appdata\local\temp\tmp2sabar\Release\users
\brendan\app
data\local\temp\tmp2sabar\src.win32-2.6
C:\Program Files\Microsoft Visual Studio 9.0\VC\BIN\cl.exe /c /nologo /
Ox /MD /W
3 /GS- /DNDEBUG -Ic:\users\brendan\appdata\local\temp\tmp2sabar
\src.win32-2.6 -I
C:\Python26\lib\site-packages\numpy\core\include -IC:\Python26\include
-IC:\Pyth
on26\PC /Tcc:\users\brendan\appdata\local\temp\tmp2sabar
\src.win32-2.6\inrngmodu
le.c /Foc:\users\brendan\appdata\local\temp\tmp2sabar\Release\users
\brendan\appd
ata\local\temp\tmp2sabar\src.win32-2.6\inrngmodule.obj
Found executable C:\Program Files\Microsoft Visual Studio 9.0\VC\BIN
\cl.exe
C:\Program Files\Microsoft Visual Studio 9.0\VC\BIN\cl.exe /c /nologo /
Ox /MD /W
3 /GS- /DNDEBUG -Ic:\users\brendan\appdata\local\temp\tmp2sabar
\src.win32-2.6 -I
C:\Python26\lib\site-packages\numpy\core\include -IC:\Python26\include
-IC:\Pyth
on26\PC /Tcc:\users\brendan\appdata\local\temp\tmp2sabar
\src.win32-2.6\fortranob
ject.c /Foc:\users\brendan\appdata\local\temp\tmp2sabar\Release\users
\brendan\ap
pdata\local\temp\tmp2sabar\src.win32-2.6\fortranobject.obj
compiling Fortran sources
Fortran f77 compiler: C:\Program Files\pythonxy\mingw\bin\gfortran.exe
-Wall -ff
ixed-form -fno-second-underscore -mno-cygwin -O3 -funroll-loops
Fortran f90 compiler: C:\Program Files\pythonxy\mingw\bin\gfortran.exe
-Wall -fn
o-second-underscore -mno-cygwin -O3 -funroll-loops
Fortran fix compiler: C:\Program Files\pythonxy\mingw\bin\gfortran.exe
-Wall -ff
ixed-form -fno-second-underscore -mno-cygwin -Wall -fno-second-
underscore -mno-c
ygwin -O3 -funroll-loops
compile options: '-Ic:\users\brendan\appdata\local\temp\tmp2sabar
\src.win32-2.6
-IC:\Python26\lib\site-packages\numpy\core\include -IC:
\Python26\include -IC:\Py
thon26\PC -c'
gfortran.exe:f77: inrng.f
copying c:\program files\pythonxy\mingw\lib\gcc
\mingw32\4.4.0\libgfortran.a -> c
:\users\brendan\appdata\local\temp\tmp2sabar\Release\gfortran.lib
copying c:\program files\pythonxy\mingw\lib\gcc\mingw32\4.4.0\libgcc.a
-> c:\use
rs\brendan\appdata\local\temp\tmp2sabar\Release\gcc.lib
C:\Program Files\Microsoft Visual Studio 9.0\VC\BIN\link.exe /DLL /
nologo /INCRE
MENTAL:NO /LIBPATH:"c:\program files\pythonxy\mingw\lib\gcc
\mingw32\4.4.0" /LIBP
ATH:C:\Python26\libs /LIBPATH:C:\Python26\PCbuild /LIBPATH:c:\users
\brendan\appd
ata\local\temp\tmp2sabar\Release /LIBPATH:C:\Python26\libs /LIBPATH:C:
\Python26\
PCbuild gfortran.lib gcc.lib mingw32.lib mingwex.lib /EXPORT:initinrng
c:\users\
brendan\appdata\local\temp\tmp2sabar\Release\users\brendan\appdata
\local\temp\tm
p2sabar\src.win32-2.6\inrngmodule.obj c:\users\brendan\appdata\local
\temp\tmp2sa
bar\Release\users\brendan\appdata\local\temp\tmp2sabar
\src.win32-2.6\fortranobje
ct.obj c:\users\brendan\appdata\local\temp\tmp2sabar\Release\inrng.o /
OUT:.\inrn
g.pyd /IMPLIB:c:\users\brendan\appdata\local\temp\tmp2sabar\Release
\users\brenda
n\appdata\local\temp\tmp2sabar\src.win32-2.6\inrng.lib /MANIFESTFILE:c:
\users\br
endan\appdata\local\temp\tmp2sabar\Release\users\brendan\appdata\local
\temp\tmp2
sabar\src.win32-2.6\inrng.pyd.manifest
Found executable C:\Program Files\Microsoft Visual Studio 9.0\VC\BIN
\link.exe
LINK : fatal error LNK1181: cannot open input file 'mingw32.lib'
error: Command "C:\Program Files\Microsoft Visual Studio 9.0\VC\BIN
\link.exe /DL
L /nologo /INCREMENTAL:NO /LIBPATH:"c:\program files\pythonxy\mingw\lib
\gcc\ming
w32\4.4.0" /LIBPATH:C:\Python26\libs /LIBPATH:C:\Python26\PCbuild /
LIBPATH:c:\us
ers\brendan\appdata\local\temp\tmp2sabar\Release /LIBPATH:C:
\Python26\libs /LIBP
ATH:C:\Python26\PCbuild gfortran.lib gcc.lib mingw32.lib mingwex.lib /
EXPORT:ini
tinrng c:\users\brendan\appdata\local\temp\tmp2sabar\Release\users
\brendan\appda
ta\local\temp\tmp2sabar\src.win32-2.6\inrngmodule.obj c:\users\brendan
\appdata\l
ocal\temp\tmp2sabar\Release\users\brendan\appdata\local\temp\tmp2sabar
\src.win32
-2.6\fortranobject.obj c:\users\brendan\appdata\local\temp\tmp2sabar
\Release\inr
ng.o /OUT:.\inrng.pyd /IMPLIB:c:\users\brendan\appdata\local\temp
\tmp2sabar\Rele
ase\users\brendan\appdata\local\temp\tmp2sabar
\src.win32-2.6\inrng.lib /MANIFEST
FILE:c:\users\brendan\appdata\local\temp\tmp2sabar\Release\users
\brendan\appdata
\local\temp\tmp2sabar\src.win32-2.6\inrng.pyd.manifest" failed with
exit status
1181

I performed a search for 'mingw32.lib' in the Python(x,y) Program
Files directory with no luck. There is no separate MinGW install
directory in Program Files.

Any ideas as to why this doesn't work out of the box? and how I might
fix it?

Brendan

Pierre Raybaut

unread,
Dec 28, 2009, 12:21:57 PM12/28/09
to python(x,y)
Hi,

The easiest way to build Fortran extensions is to use a 'setup.py'
script. And then build extensions in-place with 'python setup.py
build_ext -c mingw32 --inplace' (specify the option '--
fcompiler=gfortran' should not be necessary in this case). The option
'-c mingw32' will tell f2py (through distutils/numpy extension) to use
MinGW instead of VC++ to build the extensions.

HTH
Pierre

Brendan Arnold

unread,
Dec 28, 2009, 2:42:48 PM12/28/09
to pyth...@googlegroups.com
Thanks for the reply Pierre,

For what its worth, the f2py script did work when I installed MinGW
separate from the Python(x,y) package in the default location of
C:\MinGW and ran the following,

f2py.py -c --f77exec="C:\MinGw\bin\g77.exe" -m <modname> <fortran source file>

I've only just started dabbling with speeding up portions of code with
FORTRAN, maybe I will have to learn the use of setup.py when my needs
become more demanding.

Thanks again!

Brendan

> --
>
> You received this message because you are subscribed to the Google Groups "python(x,y)" group.
> To post to this group, send email to pyth...@googlegroups.com.
> To unsubscribe from this group, send email to pythonxy+u...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/pythonxy?hl=en.
>
>
>

Pierre Raybaut

unread,
Dec 28, 2009, 5:29:23 PM12/28/09
to python(x,y)
BTW, I think passing the option '--fcompiler=gfortran' to f2py should
work wherever MinGW is installed (if the MinGW 'bin' directory is in
PATH of course, which is the case with the Python(x,y) MinGW plugin).

Regarding setup.py and Fortran extensions, that is fairly easy to do,
I'll post an example if you're interested.

Cheers,
Pierre

On 28 déc, 20:42, Brendan Arnold <brendanarn...@gmail.com> wrote:
> Thanks for the reply Pierre,
>
> For what its worth, the f2py script did work when I installed MinGW
> separate from the Python(x,y) package in the default location of
> C:\MinGW and ran the following,
>
> f2py.py -c --f77exec="C:\MinGw\bin\g77.exe" -m <modname> <fortran source file>
>
> I've only just started dabbling with speeding up portions of code with
> FORTRAN, maybe I will have to learn the use of setup.py when my needs
> become more demanding.
>
> Thanks again!
>
> Brendan
>

M. Faust

unread,
Dec 29, 2009, 10:59:17 AM12/29/09
to pyth...@googlegroups.com
I have installed Python(x,y) 2.6.2 as well and I'm using the f2py oprions
f2py.py -c --compiler=mingw32 --fcompiler=gnu95 -m ...
which works well under MS Vista (32 bit). Good luck!
Markus

On 28.12.2009 23:29, Pierre Raybaut wrote:
> BTW, I think passing the option '--fcompiler=gfortran' to f2py should
> work wherever MinGW is installed (if the MinGW 'bin' directory is in
> PATH of course, which is the case with the Python(x,y) MinGW plugin).
>
> Regarding setup.py and Fortran extensions, that is fairly easy to do,
> I'll post an example if you're interested.
>
> Cheers,
> Pierre
>

Brendan Arnold

unread,
Dec 29, 2009, 9:06:13 PM12/29/09
to pyth...@googlegroups.com
Thanks Markus, that works for me as well (Windows 7 32 bit) using the
Python(x,y) installed MinGW

Brendan

On Tue, Dec 29, 2009 at 3:59 PM, M. Faust <markus...@t-online.de> wrote:
> I have installed Python(x,y) 2.6.2 as well and I'm using the f2py oprions
> f2py.py -c --compiler=mingw32 --fcompiler=gnu95 -m ...
> which works well under MS Vista (32 bit). Good luck!
> Markus
>
> On 28.12.2009 23:29, Pierre Raybaut wrote:
>> BTW, I think passing the option '--fcompiler=gfortran' to f2py should
>> work wherever MinGW is installed (if the MinGW 'bin' directory is in
>> PATH of course, which is the case with the Python(x,y) MinGW plugin).
>>
>> Regarding setup.py and Fortran extensions, that is fairly easy to do,
>> I'll post an example if you're interested.
>>
>> Cheers,
>> Pierre
>>

>> On 28 déc, 20:42, Brendan Arnold<brendanarn...@gmail.com>  wrote:

Reply all
Reply to author
Forward
0 new messages