LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

f2py

Fortran to Python interface generator

TLDR

Generate Python wrapper for Fortran
$ f2py -c [module.f90] -m [module_name]
copy
Create signature file
$ f2py [module.f90] -h [module.pyf]
copy
Build with specific compiler
$ f2py -c --fcompiler=[gfortran] [module.f90] -m [module_name]
copy
Link external libraries
$ f2py -c [module.f90] -m [module_name] -l[blas]
copy
Show available compilers
$ f2py --help-fcompiler
copy

SYNOPSIS

f2py [options] fortran-files [options]

DESCRIPTION

f2py (Fortran to Python) is a NumPy tool that creates Python bindings for Fortran code. It generates wrapper modules that allow calling Fortran subroutines and functions directly from Python.The tool automatically handles type conversion between Python/NumPy arrays and Fortran arrays. It parses Fortran source code or signature files to determine interfaces, then generates C wrapper code compiled into a Python extension module.f2py enables using high-performance Fortran libraries in Python scientific computing workflows without rewriting existing code.

PARAMETERS

FORTRAN-FILES

Fortran source files (.f, .f90, .f95).
-c
Compile and build extension module.
-m NAME
Set module name.
-h FILE
Generate signature file.
--fcompiler NAME
Specify Fortran compiler.
-l LIBRARY
Link with library.
-L PATH
Library search path.
-I PATH
Include search path.
--help-fcompiler
List available Fortran compilers.
--help
Display help information.

INSTALL

sudo apt install python3-numpy
copy
sudo dnf install python3-numpy
copy
sudo apk add py3-numpy-f2py
copy

CAVEATS

Requires Fortran compiler and NumPy installation. Complex Fortran constructs may need signature file tweaks. Array ordering differs between Fortran (column-major) and C (row-major).

HISTORY

f2py was created by Pearu Peterson in the late 1990s and became part of NumPy. It bridges Python's scientific computing ecosystem with decades of Fortran numerical libraries, enabling their continued use in modern Python workflows.

SEE ALSO

python(1), gfortran(1), cython(1)

Braincup
Open source brain training for math, memory and focus
Braincup mini-games
41 mini-games · Apache-2.0
No ads · No tracking
Play in browser
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid
276 stars
From the maker of Linux Command Library
Copied to clipboard
Braincup
Open source brain training for math, memory and focus. 41 mini-games, from mental arithmetic to Sudoku, N-Back and Solo Chess.
Apache-2.0 licensed · No ads · No tracking · No account
From the maker of Linux Command Library
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid