f2py on Windows including AppVeyor CI

less than 1 minute read

Related: AppVeyor Windows/Linux CI templates for Python and Fortran

Importing Fortran libraries from Python is easy and highly effective. We write modern Fortran code from scratch explicitly for the purpose of importing into Python. Here is an example .appveyor.yml script useful for CI with f2py.

Note: the pyproject.toml below is also required.

- Visual Studio 2017
- Ubuntu

stack: python 3

  PY_DIR: C:\Python36-x64
  MINGW_DIR: C:\mingw-w64\x86_64-7.2.0-posix-seh-rt_v5-rev1\mingw64\bin

clone_depth: 3

build: off

- cmd: set PATH=%PY_DIR%;%PY_DIR%\Scripts;%PATH%
- cmd: set PATH=%MINGW_DIR%;%PATH%

- pip install -e .[tests]
- cmd: del *.pyd
- cmd: python setup.py build_ext --inplace --compiler=mingw32

test_script: pytest -rsv

Why do we first pip install? To ensure Numpy is installed before building with pyproject.toml:

requires = ["setuptools", "wheel", "numpy"] 

For Windows only, this will in general create corrupted .pyd on Windows, so as in .appveyor.yml above, we delete these .pyd files and generate with MinGW compiler. This two-step process can be avoided (on Windows) by creating file c:\Anaconda\Lib\distutils\distutils.cfg containing:


Leave a Comment