Skip to content

Instantly share code, notes, and snippets.

@Rockyspade
Forked from shimizukawa/PIL_build.rst
Last active August 29, 2015 14:13
Show Gist options
  • Save Rockyspade/0e6931ae0e5d25b5bf51 to your computer and use it in GitHub Desktop.
Save Rockyspade/0e6931ae0e5d25b5bf51 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.6 (x32|x64):VisualC++ 2008 Express SP1 + Windows SDK 2008
Python-2.7 (x32|x64):VisualC++ 2008 Express SP1 + Windows SDK 2008

Python-2.4 and 2.5 need VisualStudio 7.1. see also https://gist.github.com/shimizukawa/4634344

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

Build process for Python-2.7

open console for build

  1. invoke Windows SDK's CMD Shell from Start -> Microsoft Windows SDK v6.1 -> CMD Shell
  2. type setenv /x86 /release or setenv /x64 /release which you want.
  3. type set libpath=dummy

build freetype

  1. extract freetype-2.4.11.tar.bz2 into C:\opt\freetype-2.4.11
  2. cd builds\win32\vc2008
  3. (Win64): open *.sln, *.vcproj by text editor and replace Win32 with x64.
  4. (Win32): vcbuild.exe freetype.sln /rebuild "LIB Release|Win32"
    (Win64): vcbuild.exe freetype.sln /rebuild "LIB Release|x64"
  5. done! You got objs\win32\vc2008\freetype2411.lib.
  6. 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. nmake -f makefile.vc
  4. done! You got libjpeg.lib.

build LittleCMS

  1. extract lcms-1.19.zip into C:\opt\lcms-1.19
  2. cd Projects\VC2008
  3. (Win64): open *.sln, *.vcproj by text editor and replace Win32 with x64.
  4. (Win32): vcbuild.exe lcms.sln /rebuild "Release|Win32"
    (Win64): vcbuild.exe lcms.sln /rebuild "Release|x64"
  5. 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. cd C:\opt\tcl8.5.13\win
  3. nmake -f makefile.vc INSTALLDIR=C:\opt\tcl release
  4. nmake -f makefile.vc INSTALLDIR=C:\opt\tcl install
  5. cd C:\lib\tk8.5.13\win
  6. nmake -f makefile.vc TCLDIR=..\\..\\tcl8.5.13 INSTALLDIR=C:\opt\tcl release
  7. nmake -f makefile.vc TCLDIR=..\\..\\tcl8.5.13 INSTALLDIR=C:\opt\tcl install
  8. 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. cd contrib\vstudio\vc9
  3. (Win64): open *.sln, *.vcproj by text editor and replace Win32 with x64.
  4. (Win32): vcbuild.exe zlibstat.vcproj /rebuild "ReleaseWithoutAsm|Win32"
    (Win64): vcbuild.exe zlibstat.vcproj /rebuild "ReleaseWithoutAsm|x64"
  5. done! You got contrib\vstudio\vc9\(x86|x64)\ZlibStatReleaseWithoutAsm\zlibstat.lib.
  6. rename zlibstat.lib to zlib.lib

build PIL

  1. extract PIL source into C:\opt\pillow

  2. write setup.cfg:

    [build_ext]
    library_dirs = C:\opt\freetype-2.4.11\objs\win32\vc2008\freetype2411.lib;C:\opt\jpeg-6b;C:\opt\lcms-1.19\Lib\MS;C:\opt\tcl;C:\opt\zlib-1.2.7\contrib\vstudio\vc9\x64\ZlibStatReleaseWithoutAsm;
    include_dirs = C:\opt\freetype-2.4.11\include;C:\opt\jpeg-6b;C:\opt\lcms-1.19\include;C:\opt\tcl\include;C:\opt\zlib-1.2.7;
    
  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 if you want::

    python-2.7 -S setup.py bdist_wininst

  6. make binary egg package if you want::

    python-2.7 -S setup.py bdist_egg

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