Linux Commands Examples

A great documentation place for Linux commands


Fortran to Python interface generator

see also : python


(1) To construct extension module sources:

f2py [<options>] <fortran files> [[[only:]||[skip:]] <fortran functions> ] [: <fortran files> ...]

(2) To compile fortran files and build extension modules:

f2py -c [<options>, <config_fc options>, <extra options>] <fortran files>

(3) To generate signature files:

f2py -h <filename.pyf> ...< same options as in (1) >

add an example, a script, a trick and tips

: email address (won't be displayed)
: name

Step 2

Thanks for this example ! - It will be moderated and published shortly.

Feel free to post other examples
Oops ! There is a tiny cockup. A damn 404 cockup. Please contact the loosy team who maintains and develops this wonderful site by clicking in the mighty feedback button on the side of the page. Say what happened. Thanks!


f2py -c tmodtom.f -m tmodtom
f2py -c claret4ppy.f -m claret4ppy
f2py -c claretquadpy.f -m claretquadpy
f2py -c xcorr.pyf xcorr.c
f2py -c -m _psmout psmout.f
f2py -c -m _pspier pspier.f
f2py -c -m _toeplitz toeplitz.f90
f2py -c -m pysimpson simpson.f
f2py --f90exec=ifort -c -m gridder_fc gridder_fc.f90
f2py --f90exec=gfortran -c -m gridder_fc gridder_fc.f90


This program generates a Python C/API file (<modulename>module.c) that contains wrappers for given Fortran or C functions so that they can be called from Python. With the -c option the corresponding extension modules are built.


-h <filename>

Write signatures of the fortran routines to file <filename> and exit. You can then edit <filename> and use it instead of <fortran files>. If <filename>==stdout then the signatures are printed to stdout.

<fortran functions>

Names of fortran routines for which Python C/API functions will be generated. Default is all that are found in <fortran files>.


Ignore fortran functions that follow until ’:’.


Use only fortran functions that follow until ’:’.


Get back to <fortran files> mode.

-m <modulename>

Name of the module; f2py generates a Python/C API file <modulename>module.c or extension module <modulename>. Default is ´untitled´.


Do [not] lower the cases in <fortran files>. By default, --lower is assumed with -h key, and --no-lower without -h key.

--build-dir <dirname>

All f2py generated files are created in <dirname>. Default is tempfile.mktemp().


Overwrite existing signature file.


Create (or not) <modulename>module.tex. Default is --no-latex-doc.


Create ’incomplete’ LaTeX document (without commands \documentclass, \tableofcontents, and \begin{document}, \end{document}).


Create (or not) <modulename>module.rst. Default is --no-rest-doc.


Create C/API code that reports the state of the wrappers during runtime. Useful for debugging.


Add CPP #include statement to the C/API code. <includefile> should be in the format of either ’"filename.ext"’ or ’<filename.ext>’. As a result <includefile> will be included just before wrapper functions part in the C/API code. The option is depreciated, use ’usercode’ statement in signature files instead.


Create Fortran subroutine wrappers to Fortran 77 functions. --wrap-functions is default because it ensures maximum portability/compiler independence.

--help-link [..]

List system resources found by [..] may contain a list of resources names. See also --link-<resource> switch below.


Run quietly.


Run with extra verbosity.


Print f2py version ID and exit.

--include_paths path1:path2:...

Search include files (that f2py will scan) from the given directories.

config fc options

The following options are effective only when -c switch is used.

List available Fortran compilers [DEPRECIATED].


Specify Fortran compiler type by vendor.


Specify C compiler type (as defined by distutils)


Specify the path to F77 compiler [DEPRECIATED].


Specify the path to F90 compiler [DEPRECIATED].


List available Fortran compilers and exit.


Specify the path to F77 compiler.


Specify the path to F90 compiler.


Specify F77 compiler flags.


Specify F90 compiler flags.


Specify optimization flags.


Specify architecture specific optimization flags.


Compile without optimization.


Compile without arch-dependent optimization.


Compile with debugging information.


Copyright (c) 1999, 2000, 2001, 2002, 2003, 2004, 2005 Pearu Peterson

extra options

The following options are effective only when -c switch is used.

Link extension module with <resource> as defined by numpy_distutils/ E.g. to link with optimized LAPACK libraries (vecLib on MacOSX, ATLAS elsewhere), use --link-lapack_opt. See also --help-link switch.

-L/path/to/lib/ -l<libname>
-D<define> -U<name> -I/path/to/include/
<filename>.o <filename>.so <filename>.a

Macros that might be required with non-gcc Fortran compilers.


To print out a performance report of F2PY interface when python exits. Available for Linux.


To send a message to stderr whenever F2PY interface makes a copy of an array. Integer <int> sets the threshold for array sizes when a message should be shown.

internet resources

Main website:

User’s Guide:

Mailing list:

Scipy website:


NumPy License


Python 1.5.2 or higher (2.x is supported).

Numerical Python 13 or higher (20.x,21.x,22.x,23.x are supported).

Optional Numarray 0.9 or higher partially supported.

numpy_distutils from Scipy (can be downloaded from F2PY homepage)




For instructions on reporting bugs, see

see also



Pearu Peterson <pearu[:at:]cens.ioc[:dot:]ee>

How can this site be more helpful to YOU ?

give  feedback