Simple examples of using
f2py to get high-speed Fortran integrated with Python easily.
These examples are also useful to troubleshoot problems with
Fortran compiler is needed:
brew install gcc
apt install gfortranor
yum install gfortran
pip install -e .
This will compile the Fortran code (in
It creates a file
* depends on operating system and Python version:
You will see the output:
x = 3 y = 2 x * y = 6.0 Your system did this in Python using Fortran-compiled library
Fortran comment syntax
Fortran 77 is officially full-line comments only. Inline comments are
not allowed with
f2py as a result in Fortran 77 files. Demonstrate
f2py -m badcomment -c badcomment.f
f2py normally Just Works on Linux, Mac and
Windows Subsystem for Linux.
However, Windows itself can be more challenging due to inconsistencies in Microsoft Visual Studio.
See the Windows f2py installation guide and troubleshooting guide.