Skip to content

Instantly share code, notes, and snippets.

@adrianer
Forked from shimizukawa/PIL_build.rst
Last active March 6, 2018 14:23
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save adrianer/4672457 to your computer and use it in GitHub Desktop.
Save adrianer/4672457 to your computer and use it in GitHub Desktop.

PIL(Pillow) build on Windows (32bit & 64bit)

If you want to build PIL on Windows, you need to prepare few external libraries. Although some libraries did not provide static library for windows 32/64 bits then you need to build these libraries by your hand too. Also, PIL will load by python at last then you are recommended to use same compiler with python to build libraries.

Target PIL and versions

Pillow

1.7.8 for Python 2.7: src

Required compilers

Python-2.7

VisualC++ 2008 Express SP1 + Windows SDK 7.0

Required libraries and versions

freetype2

2.4.11 src

jpeg6b

6b 27-Mar-1998 src

LittleCMS

1.19 src

tcl

8.5.13 src

tk

8.5.13 src

zlib

1.2.7 src

Required patches

for jpeg

src

for freetype, lcms, zlib and Pillow

src

Build process for Python-2.7

win32-only

  1. make sure C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin is in your PATH.

win64-only

  1. make sure C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin\amd64 is in your PATH.
  2. Copy this file:

    C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin\vcvars64.bat to this follow folder and rename the file (vcvars64.bat to vcvarsamd64.bat): C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin\amd64\vcvarsamd64.bat

build freetype

  1. extract freetype-2.4.11.tar.bz2 into C:\opt\freetype-2.4.11
  2. apply the ft2411_windows.patch patch
  3. cd builds\win32\vc2008
  4. (Win32): vcvars32.bat

    (Win64): vcvarsamd64.bat

  5. (Win32): VCExpress.exe freetype.sln /rebuild "LIB Release|Win32"

    (Win64): vcbuild.exe freetype.sln /rebuild "LIB Release|x64"

  6. done! You got objs\win32\vc2008\freetype2411.lib.
  7. rename freetype2411.lib to freetype.lib

build jpeg6b

  1. extract jpegsr6b.zip into C:\opt\jpeg-6b
  2. rename jconfig.vc to jconfig.h
  3. extract the jpeg-6b.sln and jpeg-6b.vcproj from the jpeg6bvcconf-patch to C:\opt\jpeg-6b
  4. (Win32): vcvars32.bat

    (Win64): vcvarsamd64.bat

  5. (Win32): VCExpress.exe jpeg-6b.sln /rebuild "Release|Win32"

    (Win64): vcbuild.exe jpeg-6b.sln /rebuild "Release|x64"

  6. done! You got Release\jpeg-6b.lib.
  7. rename jpeg-6b.lib to libjpeg.lib

build LittleCMS

  1. extract lcms-1.19.zip into C:\opt\lcms-1.19
  2. apply the lcms119_windows.patch patch
  3. cd Projects\VC2008
  4. (Win32): vcvars32.bat

    (Win64): vcvarsamd64.bat

  5. (Win32): VCExpress.exe lcms.sln /rebuild "Release|Win32"

    (Win64): vcbuild.exe lcms.sln /rebuild "Release|x64"

  6. done! You got Lib\MS\lcms.lib.

Note

You need to choose 1.x series of Little CMS for PIL.

build tcl/tk

  1. extract tcl8.5.13-src.zip and tk8.5.13-src.zip
  2. (Win32): vcvars32.bat

    (Win64): vcvarsamd64.bat

  3. cd C:\opt\tcl8.5.13\win
  4. nmake -f makefile.vc INSTALLDIR=C:\opt\tcl release
  5. nmake -f makefile.vc INSTALLDIR=C:\opt\tcl install
  6. cd C:\lib\tk8.5.13\win
  7. nmake -f makefile.vc TCLDIR=..\\..\\tcl8.5.13 INSTALLDIR=C:\opt\tcl release
  8. nmake -f makefile.vc TCLDIR=..\\..\\tcl8.5.13 INSTALLDIR=C:\opt\tcl install
  9. done! you got C:\opt\tcl\lib\tcl85.lib and C:\opt\tcl\lib\tk85.lib

build zlib

  1. extract zlib127.zip into C:\opt\zlib-1.2.7
  2. apply the zlib127_windows.patch patch
  3. cd contrib\vstudio\vc9
  4. (Win32): vcvars32.bat

    (Win64): vcvarsamd64.bat

  5. (Win32): VCExpress.exe zlibstat.vcproj /rebuild "ReleaseWithoutAsm|Win32"

    (Win64): vcbuild.exe zlibstat.vcproj /rebuild "ReleaseWithoutAsm|x64"

  6. done! You got contrib\vstudio\vc9\(x86|x64)\ZlibStatReleaseWithoutAsm\zlibstat.lib.
  7. rename zlibstat.lib to zlib.lib

build PIL

  1. extract PIL source into C:\opt\pillow
  2. apply the pillow178_win(32|64).patch patch
  3. build (with inplace option for selftest)::

    python-2.7 -S setup.py build_ext -i build

  4. self test::

    python-2.7 -S selftest

  5. make windows installer::

    python-2.7 -S setup.py bdist_wininst

@shimizukawa
Copy link

Thanks! I could build x64 Pillow binaries but have a little difference.

  • Patches did not fit then I have replaced the "Win32" keyword with "x64" in *.vcproj, *.sln
  • WindowsSDK7.0 not working for my environment (install vc10 compiler) then I use WindowsSDK2008 finally.
  • I could use C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin\vcvars64.bat without copying into amd64.

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