This is an archival dump of old wiki content --- see scipy.org for current material.
Please see https://docs.scipy.org/doc/numpy/f2py/

F2PY - Fortran to Python interface generator

Author:: Pearu Peterson < pearu.peterson@gmail.com >

Introduction

F2PY is a tool that provides an easy connection between Python and Fortran languages. F2PY is part of NumPy.

F2PY creates extension modules from (handwritten or F2PY generated) signature files or directly from Fortran sources.

The generated extension modules facilitate:

In addition, F2PY can build the generated extension modules to shared libraries with only one command. F2PY uses the numpy.distutils module from NumPy that supports a number of major Fortran compilers. F2PY generated extension modules depend on NumPy that provides a fast multi-dimensional array language facility to Python. For building extension modules with Numeric or Numarray array backend, one can use the older and unmaintained version of F2PY: f2py2e.

Main features

Here follows a more detailed list of F2PY features:

The syntax of signature files is borrowed from the Fortran 90/95 language specification and has some F2PY specific extensions. The signature files can be modified to dictate how Fortran (or C) programs are called from Python:

Prerequisites

Since F2PY is a part of NumPy, the same prerequisites apply, that is, Python 2.3 or newer with distutils package must be installed.

Of course, to build extension modules, one also needs a working C and/or Fortran compilers installed.

Download and installation

Download and install NumPy in the usual way: python setup.py install.

Usage

To check if F2PY is installed correctly, run

SciPy: F2py (last edited 2015-10-24 17:48:23 by anonymous)