Running Fortran from Python with F2PY

The last post looking at using the Python F2Py package said:

It is also necessary to install a Fortran compiler.  After some trial and error I found that the MinGW (Minimalist GNU for Windows) package worked well.

Trying some simple examples on a new computer however yielded a variety of “unable to find” errors, and a search on each returned a range of conflicting suggestions on how they might be fixed.  Eventually the following (relatively straightforward) process worked for me:

  • Uninstall Python and install the latest version of Anaconda Python, appropriate to the operating system.  I actually had 2 versions of 32 bit Python in different folders, on 64 bit Windows, which may or may not have contributed to the problems.
  • Install the version of MinGW provided with the Anaconda download, from the command line using:
    conda install mingw
    from the top level Anaconda folder.  There is an installation package available on the MinGW site, but I couldn’t get F2Py to work with that installation.
  • That’s all

I had previously installed Visual Studio Express 2015.  It is not clear to me whether this is required or not.

After this process I found that:

  • The simple examples from the F2Py tutorial worked without a problem.
  • Any example with a PRINT* statement in the Fortran code still does not compile.  I haven’t found a solution to this one yet, other than avoiding PRINT statements.
  • The callback example from the tutorial worked after adding a line to declare the FUN variable as REAL*8.  More on this one later.

I hope to have some more detailed and useful examples to present in the near future!


This entry was posted in Excel, Link to Python, NumPy and SciPy and tagged , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s