Compiling PIL for 64 bit Python in Windows 7 64 with Visual Studio 2010
I recently needed to compile PIL (Python Image Library) for Python 2.7.3 64 bit. There was very little useful information on the interwebs about it so I figured I’d jot down my solution.
The tough part for me was to figure out how to get the jpeg and zlib dependency libraries compiled and included.
PIL Source
- Download the source code for PIL for whatever Python version you need.
- Extract to some folder (Example C:/temp/PIL). Clarification: The archive contains a folder called Imaging-Version#, in the example here that directory is removed so that the files therein lives in C:/temp/PIL
The dependency libraries
You can find the source to all the available dependency libraries in C:/temp/PIL/README
Jpeg Support
- Extract the archive (Example C:/temp/jpeg-9)
- Open up a Visual Studio 2010 64 Command Prompt (Start -> All programs -> Microsoft Visual Studio 2010 -> Visual Studio Tools -> Visual Studio x64 Win64 Command Prompt (2010)
- Run the following commands:
cd C:\temp\jpeg-9
SET VS90COMNTOOLS=%VS100COMNTOOLS%
nmake -f makefile.vc setup-v10
- You now have a jpeg.vcxproj (C:/temp/jpeg-9/jpeg.vcxproj). Double click this file to open in VS2010.
- Go to Build->Configuration Manager->Active Solution Platform->New… and choose x64 in the drop down
- Close and Build Solution (F6). Once the build is complete, you will have a directory x64/Release (C:/temp/jpeg-9/x64/Release)
- Create a new directory in C:/temp/PIL called lib (C:/temp/PIL/lib)
- Inside the new directory, create another directory called jpeg (C:/temp/PIL/lib/jpeg)
- Copy all the FILES from the C:/temp/jpeg-9/x64/Release and all the FILES from C:/temp/jpeg-9 into the C:/temp/PIL/lib/jpeg folder.
- Open up C:/temp/PIL/setup.py for edit and set the jpeg root like below:
JPEG_ROOT = "C:/temp/PIL/lib/jpeg"
- To verify all went well with the jpeg dependency, in your VS Command prompt type:
cd C:\temp\PIL
"C:\Program Files\python27\python.exe" setup.py build
Note: The path to your Python install may not be the same as mine.
- You should see in the Setup Summary that jpeg support is available.
PNG support (zlib)
Note: I used the latest version from here
- Extract the archive (Example C:/temp/zlib-1.2.8)
- Go to C:/temp/zlib-1.2.8/contrib/
vstudio/vc10 - According to this page, there is a bug in the VS2010 solution. You fix it by right clicking on the zlibstat project (zlibstat.vcxproj) find and remove all instances of ZLIB_WINAPI; in the file (using your favorite text editor). When done, save it.
- Double click zlibvc.vcxproj to open it in VS2010.
- Go to Build->Configuration Manager->Active Solution Platform->New… and choose x64 in the drop down
- Close and Build Solution (F6). Once the build is complete, you will have a directory x64/Release (C:/temp/zlib-1.2.8/contrib/
vstudio/vc10/x64/Release) - Now type the following into your VS2010 64 bit command prompt (Source Info):
cd C:/temp/zlib-1.2.8
nmake -f win32\Makefile.msc AS=ml64 LOC="-DASMV -DASMINF -I." OBJA="inffasx64.obj gvmat64.obj inffas8664.obj"
- Inside the C:/temp/PIL/lib directory, create another directory called zlib (C:/temp/PIL/lib/zlib)
- Copy the source FILES in C:/temp/zlib-1.2.8 and all the files in C:/temp/zlib-1.2.8/contrib/
vstudio/vc10/x64/Release to C:/temp/PIL/lib/zlib - Open up C:/temp/PIL/setup.py for edit and set the jpeg root like below:
ZLIB_ROOT = "C:/temp/PIL/lib/zlib"
- To verify all went well with the jpeg dependency, in your VS 64 bit Command prompt type:
cd C:\temp\PIL
"C:\Program Files\python27\python.exe" setup.py build
Note: The path to your Python install may not be the same as mine.
- You should see in the Setup Summary that — ZLIB (PNG/ZIP) support available.
Final Build
- Go to C:\temp\PIL\build and delete all directories from there.
- Go back to the VS 64 bit Command prompt and type:
cd C:\temp\PIL
"C:\Program Files\python27\python.exe" setup.py build
- The files in the folder C:\temp\PIL\build\lib.win-
amd64-2.7 is your new PIL module. If you just want to bypass all this “fun”, feel free to download the PIL compiled version from here .
Enjoy,
/Christian Akesson
Leave a Reply
Want to join the discussion?Feel free to contribute!
http://mistermatti.wordpress.com/2014/02/04/maya-2014-with-pythons-pil-module/
[…] [1] http://christianakesson.com/compiling-pil […]
mistermatti has a version with freetype support (linked).
Thanks for putting it out there!
Thanks for posting the link, Christian 🙂