Pillow is a Python image library with several other libraries built-in. Because it is originally built with VC2008, we can't use the wheel package with Maya. We'll need to build it manually. I wrote this blog for Maya 2017 at first. For Maya 2018, please use replace building environment with VS2015 and Windows SDK 8.1.
VS2012 update 4
CMake > 3.3
Python 2.7.11 source code
Windows SDK 7.1A
Before we build Pillow, we need to install setup tools.
Run an VS2012 x64 Native Tools Command Prompt with administrator privilege. Set following environment variables:
Replace Maya2017 with your Maya 2017 installation path. Then make a copy of mayapy.exe in the same folder renamed as python.exe. We are going to run build commands in this command prompt later.
Download the following packages from python packages:
six, packaging, pyparsing, appdirs, setuptools, olefile, nose(for testing only)
Install them in order, using the following commands:
mayapy setup.py build
mayapy setup.py install
Copy the include folder inside python source into Maya2017/Python and copy Maya2017/libs/python27.lib into Maya2017/Python/Libs.
If the Maya/2017/Python/Libs folder doesn't exist, you'll have to create it manually. I'll recommend that you to do it at the end. I'll explain it later.
Build the Pillow imaging libraries
Here is how I built the Pillow-4.1.0 with Maya2017 and it is built with several libraries to support different image formats. For Maya 2018, you'll need to use VS2015 and some libraries are changed in Pillow 5.1/5.2. Some libraries don't provide a VS2015 solution, you could upgrade VS2012 solutions to 2015 by changing the project configuration, (e.g. toolset is Visual Studio 2015 and Platform SDK 8.1).
The build script isn't working well, so we have to build those libraries manually. You can find the required libraries inside winbuild/config.py . Please download them first.
We are going to build with MinSizeRel or Release configuration on x64 platform by default. If it is a different configuration, I'll explain it. The / is root path of each corresponding libraries' source code.
Open the solution file inside /contrib/vstudio/vc11(for Maya 2018, please use vc14), build the zlibstat project with ReleaseWithoutASM and x64 platform. Copy and rename zlibstat.lib /zlib.lib.
Copy win32.mak from Windows SDK 7.1A/include into /. Run the following command in command prompt.
nmake -f makefile.vc setup-v10
It will generate a VS2010 solution file(jpeg.sln). Open and upgrade it with VS2012. After building it, copy jpeg.lib to /.
If you are using Pillow 5.2, you'll need JPEGsr9c. It doesn't support visual studio 2012/2015. You'll need to download a Visual studio 2017 and make the project 2015 and no longer requires win32.mak.
Use CMake to generate a VS2012 solution and build the tiff project. Default configuration doesn't have AdobeDeflate and Jpeg Compression support. You can modify the config file to make tiff library support it. Zlib and jpeg configurations could be missing too.Please open advanced settings in CMake and set locations to the libraries we've built earlier. I found this when trying to build Pillow 5.2 with a forum user, here is a screenshot of his settings on his computer.
Thanks him for providing this feedback and let me use his screenshot:)
When it is build, the tiff.lib should be copied into /libtiff. If not, please copy it.
Copy /build/libtiff/tiffconf.h to /libtiff.
Copy tiff.dll to Maya2017/bin or you can copy it into PIL folder after building Pillow later. If there is a tiffxx.dll, please copy it too.
If you find unistd.h is missing, please find a dummy one from the internet. I used a file from stackoverflow and put it into VC's include folder. For VS2015, you may get a snprintf error, please remove the declarations of them in tiff libraries.
Open and upgrade /builds/windows/vc2010/freetype.sln with VS2012. After building it, copy and rename /objs/vc2012/x64/freetype271.lib to /include/freetype.lib.
Open /Projects/VC2012/lcms2.sln, build lcms2 project. Copy and rename /lib/MS/lcms2.lib to /include/lcms2.lib.
Copy lcms2.dll to Maya2017/bin or you can copy it into PIL folder after building Pillow later.
Build it with following command:
nmake -f Makefile.vc CFG=release-static RTLIBCFG=static OBJDIR=output all
Copy files from /output/release-static/x64/lib to Pillow-4.1.0/. And copy /src/webp folder to Pillow-4.1.0/libImaging
Openjpeg 2.1.2/openjpeg 2.3.0
Use CMake to generate a VS2012 solution and build openjp2 project. Create a folder named openjpeg-2.1.2(case sensitive) in /bin, Copy following files from /src/lib/openjp2 into it.
Copy openjp2.lib into Pillow4.1.0/ and copy openjp2.dll to Maya2017/bin or you can copy it into PIL folder after building Pillow later.
We can start to build Pillow now. Open setup.py and you'll find several root variables starting from line 107. Please put the path to the lib file in it. Latest ImageQuant won't be compiled with VS(allthough it claimed supporting VS2015/Vs2017 in msvc branch, but it uses OpenMP 3.0 which VS2015/2017 doesn't support when I am writing this blog), so we are ignoring it. The path of JPEG2K should be the path contains openjpeg-2.1.2/openjpeg-2.3.0 folder.
Here is how my libraries look like in Pillow setup.py(pillow 5.1)
JPEG_ROOT = "C:\\pillow-depends\\jpeg-9b"
JPEG2K_ROOT = "C:\\pillow-depends\\openjpeg-2.3.0\\bin"
ZLIB_ROOT = "C:\\pillow-depends\\zlib-1.2.11"
IMAGEQUANT_ROOT = None
TIFF_ROOT = "C:\\pillow-depends\\tiff-4.0.9\\libtiff"
FREETYPE_ROOT = "C:\\pillow-depends\\freetype-2.9\\include"
LCMS_ROOT = "C:\\pillow-depends\\lcms2-2.7\\include"
The locations of libraries:
Directory of C:\pillow-depends\freetype-2.9\include
07/09/2018 04:14 PM 44,574 freetype.lib
Directory of C:\pillow-depends\jpeg-9b
07/09/2018 03:27 PM 4,487,122 jpeg.lib
Directory of C:\pillow-depends\lcms2-2.7\include
07/09/2018 05:26 PM 76,442 lcms2.lib
Directory of C:\pillow-depends\tiff-4.0.9\libtiff
07/09/2018 04:02 PM 35,950 tiff.lib
Directory of C:\pillow-depends\zlib-1.2.11
07/09/2018 03:29 PM 728,368 zlib.lib
Directory of c:\pillow-depends\openjpeg-2.3.0\bin\openjpeg-2.3.0
10/05/2017 06:23 AM 59,369 openjpeg.h
07/09/2018 04:24 PM 342 opj_config.h
10/05/2017 06:23 AM 2,171 opj_stdint.h
Directory of E:\Pillow-5.1.0
07/09/2018 05:42 PM 1,441,052 libwebp.lib
07/09/2018 05:41 PM 701,406 libwebpdecoder.lib
07/09/2018 04:25 PM 12,796 openjp2.lib
07/09/2018 05:34 PM 942,016 webp.lib
07/09/2018 05:34 PM 29,000 webpdemux.lib
Directory of E:\Pillow-5.1.0\src\libImaging\webp
11/29/2017 04:15 AM 3,972 config.h.in
11/29/2017 04:01 AM 23,150 decode.h
11/29/2017 04:01 AM 15,606 demux.h
11/29/2017 04:01 AM 27,481 encode.h
11/29/2017 04:01 AM 3,863 format_constants.h
11/29/2017 04:01 AM 22,824 mux.h
11/29/2017 04:01 AM 3,150 mux_types.h
11/29/2017 04:01 AM 1,665 types.h
I recommend to enable DEBUG flag and copy the Python include folder after running the script. It will print debug output and automatically stops when python.h is not found. It is very useful to see if any paths are inappropriate. If everything is fine, please copy the include folder from Python 2.7.11 to Maya2017/Python.
The rest is simple, same as other python libraries:
mayapy setup.py build
mayapy setup.py install
You can test it with test-install.py. There should be 8 errors because the tiff library doesn't support certain types.
If you have a failed case in test_image.getim.py, it isn't a library issue. The test case sometimes won't work, so open the test case and modify line 13 from int to (int, long) will fix the failing case.
Enjoy it now.