Skip to content
Examples of using f2py to get high-speed Fortran integrated with Python easily
Branch: master
Clone or download
Latest commit 928736b Jun 24, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github Create FUNDING.yml Jun 12, 2019
build/bin meta Jun 11, 2019
tests build template Aug 16, 2018
.appveyor.yml appveyor bug [skip travis] Jun 19, 2019
.codeclimate.yml init [ci skip] Nov 14, 2017
.coveragerc f2py and CI template Jun 11, 2019
.flake8 f2py and CI template Jun 11, 2019
.gitattributes template Oct 23, 2017
.gitignore cmake Jun 14, 2018
.travis.yml f2py and CI template Jun 11, 2019
CMakeLists.txt cmake Jun 14, 2018
LICENSE.txt
README.md f2py and CI template Jun 11, 2019
badcomment.f
badcomment_implicit.f
f2py_demo.py cleanup Jun 14, 2018
floatPrecision.f90 init, new travis template Nov 14, 2017
floatPrecision.py
goodcomment.f init Apr 3, 2017
goodcomment.f90 init Apr 3, 2017
mypy.ini f2py and CI template Jun 11, 2019
prod.f90 cleanup Jun 14, 2018
pyproject.toml prereq Jun 24, 2019
setup.cfg
setup.py f2py and CI template Jun 11, 2019

README.md

Build Status Coverage Status Build status Maintainability

f2py Examples

Simple examples of using f2py to get high-speed Fortran integrated with Python easily. These examples are also useful to troubleshoot problems with f2py.

Build

Fortran compiler is needed:

  • Mac: brew install gcc
  • Linux: apt install gfortran or yum install gfortran
  • Windows

Install

pip install -e .

This will compile the Fortran code (in .f and .f90 files). It creates a file pyprod.* where * depends on operating system and Python version:

  • Linux/Mac: .so
  • Windows: .pyd

Examples

Fortran Intents

python f2py_demo.py

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 this with:

f2py -m badcomment -c badcomment.f

Troubleshooting f2py

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.

You can’t perform that action at this time.