# Appveyor and mingwpy to Create Python Wheels on Windows¶

TLDR; After many trials figured out how to compile FORTRAN/C libraries on Windows to be used in Python, using Appveyor, a cloud base Continuous Integration Service for Windows and mingwpy. Wish that I could say that I am a genius, but no, just persistent.

# My “wdmtoolbox”¶

I developed this Python program to work with Watershed Data Management (WDM) files that I called “wdmtoolbox” (clever name, heh?). It is a f2py wrapped library which means it has one “C” file that is compiled in with the FORTRAN code to form the library. That one “C” file meant that compiling on Windows was a problem.

# Python, FORTRAN, and C, O my!¶

The Windows and Python Gods don’t make it easy to compile “C” on Windows that is importable into Python. Bring on the pain…

SciPy also supports Microsoft Visual C++ (MSVC) as the C/C++ compiler
extension modules for the official binary distribution of Python, the
runtime libraries have to be compatible. As the official versions of Python
2.3/2.4/2.5 are compiled with Visual Studio 2003 (Visual Studio 7.1) and
hence linked to msvcr71, this leaves only MSVC 7.1 to build extensions for
these Python versions. This pretty much excludes the free (as in beer)
Visual Studio 2005 Express, at least if one doesn’t also want to build
Python (and all other extension modules) from sources with MSVC 8 - which
currently is not offically supported. Combining MSVC with G77 from MinGW or
Cygwin is supported, as is the combination with other Fortran compilers.


If you aren’t into the fine print it means that if you have any “C” code to compile you have to use the Microsoft compilers that match whatever was used to compile Windows Python.

# Appveyor¶

Appveyor is a Continuous Integration Service for Windows. It has hooks to github and bitbucket accounts and will download/build/install your project triggered by each commit. I took me over 125 commits to get this to work. As mentioned above, persistence, not genius.

# MinGWPy¶

Now this is real genius here. (SHOUTOUT TO https://anaconda.org/carlkl ! GREAT JOB). At least for “wdmtoolbox”, I didn’t have to worry about any of the Microsoft compiler matching Python conundrum. It just worked. You can get mingwpy by:

pip install -i https://pypi.anaconda.org/carlkl/simple mingwpy


# appveyor.yml¶

Appveyor is driven by a YML file. The file for “wdmtoolbox” is at https://github.com/timcera/wdmtoolbox/blob/master/appveyor.yml

This “appveyor.yml” creates both wheels and eggs for Python 2.7 and 3.4, for both 32 and 64-bit.

Previous: Testing Images