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

  1. Download the source code for PIL for whatever Python version you need.
  2. 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
  1. Extract the archive (Example C:/temp/jpeg-9)
  2. 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)
  3. Run the following commands:

cd C:\temp\jpeg-9
SET VS90COMNTOOLS=%VS100COMNTOOLS%
nmake -f makefile.vc setup-v10
    
  1. You now have a jpeg.vcxproj (C:/temp/jpeg-9/jpeg.vcxproj). Double click this file to open in VS2010.
  2. Go to Build->Configuration Manager->Active Solution Platform->New… and choose x64 in the drop down
  3. Close and Build Solution (F6). Once the build is complete, you will have a directory x64/Release (C:/temp/jpeg-9/x64/Release)
  4. Create a new directory in C:/temp/PIL called lib (C:/temp/PIL/lib)
  5. Inside the new directory, create another directory called jpeg (C:/temp/PIL/lib/jpeg)
  6. 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.
  7. Open up C:/temp/PIL/setup.py for edit and set the jpeg root like below:

JPEG_ROOT = "C:/temp/PIL/lib/jpeg"
    
  1. 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.

  1. You should see in the Setup Summary that jpeg support is available.
PNG support (zlib)

Note: I used the latest version from here

  1. Extract the archive (Example C:/temp/zlib-1.2.8)
  2. Go to C:/temp/zlib-1.2.8/contrib/vstudio/vc10
  3. 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.
  4. Double click zlibvc.vcxproj to open it in VS2010.
  5. Go to Build->Configuration Manager->Active Solution Platform->New… and choose x64 in the drop down
  6. 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)
  7. 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"
    
  1. Inside the C:/temp/PIL/lib directory, create another directory called zlib (C:/temp/PIL/lib/zlib)
  2. 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
  3. Open up C:/temp/PIL/setup.py for edit and set the jpeg root like below:

ZLIB_ROOT = "C:/temp/PIL/lib/zlib"
    
  1. 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.

  1. You should see in the Setup Summary that — ZLIB (PNG/ZIP) support available.
Final Build
  1. Go to C:\temp\PIL\build and delete all directories from there.
  2. Go back to the VS 64 bit Command prompt and type:

cd C:\temp\PIL
"C:\Program Files\python27\python.exe" setup.py build
    
  1. 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

3 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply to mistermatti Cancel reply

Your email address will not be published. Required fields are marked *