Wednesday, February 6, 2013

F2PY on 64bit Windows (python2.7)

I am writing this post because after hours of frustration I want to share the solution that I found to get F2PY running on a 64 bit windows machine. Ok, here is how it worked out for me,...

If you have old python stuff on your computer, than entirely remove it and download and install components in the following order:

.) Python 2.7.3 Windows X86-64 Installer under http://www.python.org/getit/
.) numpy-unoptimized-1.6.2.win-amd64-py2.7.‌exe under http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy

Then download and extract
.) mingw-w64 under http://sourceforge.net/projects/mingw-w64/
From the extracted directories copy mingw to your c:\mingw

After that, go to your environment variables (under System) and add
.) C:\Python27\Scripts
.) C:\mingw\bin 
to the PATH variable

Add also .py to the PATHEXT variable.


To use F2PY now write: 

f2py -c --fcompiler=gnu95 --compiler=mingw32 -m yourmodulename yourfortranfile

Important note:
I still got an error on my system saying:

"File "C:\Python26\lib\site-packages\numpy\distutils\fcompiler\gnu.py", line 331, in get_libraries raise NotImplementedError("Only MS compiler supported with gfortran on win64") NotImplementedError: Only MS compiler supported with gfortran on win64"

I solved the problem absolutely randomly: 
I changed C:\Python27\Lib\site-packages\numpy\distutils\fcompiler\gnu.py line 331 to:

pass #raise NotImplementedError("Only MS compiler supported with gfortran on win64")

Basically I un commented the NotImplementedError and it worked fine!! GEZUZ!!

6 comments:

  1. So this is the closest solution I have come across with a problem like mine. I'm getting an error with the limits.h header while using f2py with a g77 installation. Do you think this is the solution to my problem?

    ReplyDelete
    Replies
    1. Hi Bohi.
      Sorry for the late response. Unfortunately I haven't had a problem with the limits.h header file, thus I am not sure what your problem might be related to.

      Cheers Chris.

      Delete
  2. Hi Cristian, I'm very glad to find a good tutorial of how use f2py in a system 64 bit, windows. I have just one question, after I install python, numpy and minGW, I put this code:
    f2py -c --fcompiler=gnu95 --compiler=mingw32 -m yourmodulename yourfortranfile
    in the shell? Where I put my fortran programs (what is the adress)? What is module? (I'm a beginner in python, thanks for your post!)

    ReplyDelete
    Replies
    1. Hi Felipe.

      So --fcompiler=gnu95 is a flag that specifies the fortran compiler which must be installed on your PC. --compiler=mingw32 is a flag that specifies the c compiler which must be installed on your PC as well. -m is the flag which specifies the name of the module according to 'yourmodulename; this name is the one you have to call in python. 'Yourfortranfile' is the name of the fortran file you want to compile.

      Further examples can be found here:
      http://wiki.scipy.org/F2py
      http://cens.ioc.ee/projects/f2py2e/FAQ.html
      http://www.sagemath.org/doc/numerical_sage/f2py.html

      Cheers Chris.

      Delete
  3. Hi Christian,
    I just wanted to say thank you! I had the same error (Only MS compiler supported with gfortran on win64) and uncommenting the line fixed it.

    Hours saved ... :-)

    Edgar

    ReplyDelete
  4. Thanks Christian,

    same worked for me Using Anaconda 64 bit on Win 7. MinGW installation was not needed! But changed gnu.py at Line 327 at ...\Anaconda\Lib\site-packages\numpy\distutils\fcompiler\gnu.py

    Best Regards from Vienna - Dieter

    ReplyDelete