When I needed to compile PIL (Python Image Library) for Maya & Python 2.7.3 64 bit, there was very little useful information on the interwebs about it so I figured I’d jot down the steps I went through here.
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:
1 2 3 4 |
:: Commands to be run cd C:tempjpeg-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:
1 2 |
:: Commands to be run JPEG_ROOT = "C:/temp/PIL/lib/jpeg" |
- To verify all went well with the jpeg dependency, in your VS Command prompt type:
1 2 3 |
:: Commands to be run cd C:tempPIL "C:Program Filespython27python.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):
1 2 3 |
:: Commands to be run cd C:/temp/zlib-1.2.8 nmake -f win32Makefile.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:
1 2 |
:: Commands to be run ZLIB_ROOT = "C:/temp/PIL/lib/zlib" |
- To verify all went well with the jpeg dependency, in your VS 64 bit Command prompt type:
1 2 3 |
:: Commands to be run cd C:tempPIL "C:Program Filespython27python.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.
Compile the final build
- Go to C:tempPILbuild and delete all directories from there.
- Go back to the VS 64 bit Command prompt and type:
1 2 3 |
:: Commands to be run cd C:tempPIL "C:Program Filespython27python.exe" setup.py build |
- The files in the folder C:tempPILbuildlib.win-
amd64-2.7 is your new PIL module.
Spread the knowledge