[SciPy-User] f2py fortran95 won't compile
Fri Dec 11 12:50:30 CST 2009
On Fri, Dec 11, 2009 at 1:39 AM, Joe Barfett <email@example.com> wrote:
> 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.
> 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 (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!
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:
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:
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
With those steps, the following hello.f95 file compiles for me:
subroutine foo (a)
print*, "Hello from Fortran!"
f2py -c -m hello hello.f95
More information about the SciPy-User