Skip to content

Instantly share code, notes, and snippets.

@bjoas
Created July 4, 2019 15:11
Show Gist options
  • Select an option

  • Save bjoas/933e8433455ac69ed3833d4ee2c6d952 to your computer and use it in GitHub Desktop.

Select an option

Save bjoas/933e8433455ac69ed3833d4ee2c6d952 to your computer and use it in GitHub Desktop.
Build matplotlib from source with Visual Studio 2017 on Windows x64

Matplotlib

Compile on Windows

If you e.g. would like to have a debug version of matplotlib (which is not possible to install through pip) you need to compile matplotlib from source. It is somewhat tricky but can be done like this:

  1. Install Visual Studio 2017 with Visual C++ and Windows SDK from https://visualstudio.microsoft.com/downloads/

  2. Install Python 3.7 from https://www.python.org/

  3. Download matplotlib source from https://github.com/matplotlib/matplotlib/tree/v3.1.1 and extract to matplotlib

  4. Download freetype source from https://download.savannah.gnu.org/releases/freetype/ and extract to freetype-2.10.0

    1. Open freetype-2.10.0\builds\windows\vc2010\freetype.sln in Visual Studio 2017
    2. Select target x64
    3. Right click on the freetype project and select properties
    4. Set Configuration type to Static library (.lib)
    5. Build
    6. Copy objs\freetype.lib to matplotlib\freetype.lib
  5. Download zlib soruce from https://zlib.net/ and extract to zlib

  6. Compile zlib

    1. Open VS 2017 console in folder zlib

    2. Run command

       nmake -f win32\Makefile.msc
      
    3. Copy zlib\zlib.lib to matplotlib\z.lib (note z.lib, not zlib.lib)

  7. Download libpng source from http://www.libpng.org/pub/png/libpng.html and extract to lpng1637

  8. Compile libpng

    1. Open VS 2017 console in folder lpng1637

    2. Run command

       nmake -f scripts\makefile.vcwin32
      
    3. Copy lpng1647/libpng.lib to matplotlib/png.lib

  9. Create a batch file with contents: build-matplotlib.bat

    call "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build\vcvarsall.bat" amd64
    
    SET INCLUDE=C:\Python37\SOURCE\freetype-2.10.0\include;%INCLUDE%
    SET INCLUDE=C:\Python37\SOURCE\zlib;%INCLUDE%
    SET INCLUDE=C:\Python37\SOURCE\lpng1637;%INCLUDE%
    
    cd matplotlib
    
    c:\Python37\python_d.exe setup.py build --debug install
    
    pause

    (assuming that you installed Python37 in C:\Python37 and put all code in C:\Python37\SOURCE)

  10. Run the batch file to build matplotlib

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment