[SciPy-User] f2py fortran95 won't compile

Robin robince at gmail.com
Fri Dec 11 13:50:30 EST 2009


On Fri, Dec 11, 2009 at 1:39 AM, Joe Barfett <joebarfett at yahoo.ca> wrote:
>
> Hello,
> I've been putting a lot of time and googling into trying to get f2py to work. I do large matrix operations in python using scipy and numpy. There's a few small functions I need to speed up and want to use fortran or c to do this.
> Right now I write code that needs days to run. I'm hoping that I can really speed this up. I've also bought books to help but to no avail yet. I've found python to be incredibly good for what I do, but have had a lot of trouble extending it.
> Eventually I thought I would ask for help.
> On my new computer running snow leopard I was able to install the fortran 95 compiler. I installed the gcc compilers from the xcode developer tools.
> Going into bash and typing f2p gives returns a long message ending in..
> Version:     2
> numpy Version: 1.3.0
> Requires:    Python 2.3 or higher.
> License:     NumPy license (see LICENSE.txt in the NumPy source code)
> Copyright 1999 - 2005 Pearu Peterson all rights reserved.
> http://cens.ioc.ee/projects/f2py2e/
> If I run f2py -c --help-fcompiler
> I get a lot of output, one line of which says that the GNU Fortran 95 compiler is there. So I proceeded to make hello.f as indicated in the scipy documentation. I saved it in my documents directory.
> Going back to bash, I cd into the documents directory and run
> f2py -c -m hello hello.f
> This gives me a long output that ends with the error:
> building extension "hello" sources
> f2py options: []
> f2py:> /var/folders/1I/1IOFcx8xHPWOBxtsQ1BZgE+++TI/-Tmp-/tmpWX5ghA/src.macosx-10.3-fat-2.5/hellomodule.c
> creating /var/folders/1I/1IOFcx8xHPWOBxtsQ1BZgE+++TI/-Tmp-/tmpWX5ghA
> creating /var/folders/1I/1IOFcx8xHPWOBxtsQ1BZgE+++TI/-Tmp-/tmpWX5ghA/src.macosx-10.3-fat-2.5
> Reading fortran codes...
> Reading file 'hello.f' (format:fix,strict)
> Post-processing...
> Post-processing (stage 2)...
> Building modules...
> error: f2py target file '/var/folders/1I/1IOFcx8xHPWOBxtsQ1BZgE+++TI/-Tmp-/tmpWX5ghA/src.macosx-10.3-fat-2.5/hellomodule.c' not generated
> I've been stuck trying to get up and running with extending python for months now and I'm really hoping someone can help me along. Once I can get this working, I'll start trying to send in numpy arrays and get numpy arrays back.
> I really appreciate your kind assistance. Cheers!
> joe

Hi,
I'm not sure what your actual problem is,  but perhaps it will help if
I point out the steps I followed to get it working.

Also note the f2py is part of numpy, so the numpy list (or f2py list)
might be more appropriate.

You don't specify which fortran compiler you are using. For the mac it
is generally recommended to use the gfortran build from here:
http://r.research.att.com/tools/
You will also need to install Xcode (to get c compilers).

If you are on OS X 10.6 with Python build from python.org you may need to do:
#export CC=/usr/bin/gcc-4.0
before calling f2py. This is because apple changed the default
compiler version to 4.2, but the Python binaries are built with the
older one (this is true for 2.5, I havent tried a python.org 2.6
build).

With those steps, the following hello.f95 file compiles for me:

subroutine foo (a)
      integer a
      print*, "Hello from Fortran!"
      print*, "a=",a
end

with
f2py -c -m hello hello.f95

Cheers

Robin



More information about the SciPy-User mailing list