JPEG and PNG Library Use in PIL
Question: I'm relatively new to development and I've been attempting to setup an
application I'm building in Django (on Windows 7, 64 bit) to accept image
uploads via ImageField. I initially installed PIL, but found that I needed
JPEG and PNG libraries first. So I uninstalled PIL using "pip uninstall pil"
and setup the libraries at C:\zlib-1.2.7\zlib.lib and C:\jpeg-8d\libjpeg.lib.
Afterwards, I went into the setup.py in PIL and changed the following:

    
    
        JPEG_ROOT = "C:/jpeg-8d"
        ZLIB_ROOT = "C:/zlib-1.2.7"
    

I then install via:

    
    
        pip install C:\Imaging-1.1.7\
    

I got the following at the end of the install, which suggests there's JPEG and
PNG support:

    
    
    Installing collected packages: PIL
    Running setup.py install for PIL
    WARNING: '' not a valid package name; please use only.-separated package nam
    es in setup.py
    --------------------------------------------------------------------
    PIL 1.1.7 SETUP SUMMARY
    --------------------------------------------------------------------
    version       1.1.7
    platform      win32 2.6.6 (r266:84297, Aug 24 2010, 18:46:32)
                  [MSC v.1500 32 bit (Intel)]
    --------------------------------------------------------------------
    *** TKINTER support not available (Tcl/Tk 8.5 libraries needed)
    --- JPEG support available
    --- ZLIB (PNG/ZIP) support available
    *** FREETYPE2 support not available
    *** LITTLECMS support not available
    --------------------------------------------------------------------
    To add a missing option, make sure you have the required
    library, and set the corresponding ROOT variable in the
    setup.py script.
    
    To check the build, run the selftest.py script.
    Successfully installed PIL
    Cleaning up...
    

However, I got following when testing with selftest.py, which suggests no
support:

    
    
    C:\Windows\system32>python C:\Imaging-1.1.7\selftest.py
    --------------------------------------------------------------------
    PIL 1.1.7 TEST SUMMARY
    --------------------------------------------------------------------
    Python modules loaded from C:\Users\ayan\Desktop\Imaging-1.1.7\PIL
    Binary modules loaded from C:\Python26_x86\lib\site-packages\PIL
    --------------------------------------------------------------------
    *** PIL CORE support not installed
    *** TKINTER support not installed
    *** JPEG support not installed
    *** ZLIB (PNG/ZIP) support not installed
    *** FREETYPE2 support not installed
    *** LITTLECMS support not installed
    --------------------------------------------------------------------
    

I also tried to work with a JPEG and got following IOError:

    
    
    C:\Users\Public\Pictures\Sample Pictures>python
    Python 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit (Intel)] on
    win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import PIL
    >>> import os, sys
    >>> import Image
    >>> img = Image.open(Desert.jpg)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    NameError: name 'Desert' is not defined
    >>> img = Image.open("Desert.jpg")
    >>> img.save("Desert_test.jpg")
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "C:\Python26_x86\lib\site-packages\PIL\Image.py", line 1406, in save
        self.load()
      File "C:\Python26_x86\lib\site-packages\PIL\ImageFile.py", line 189, in load
        d = Image._getdecoder(self.mode, d, a, self.decoderconfig)
      File "C:\Python26_x86\lib\site-packages\PIL\Image.py", line 385, in _getdecode
    r
        raise IOError("decoder %s not available" % decoder_name)
    IOError: decoder jpeg not available
    

This is somewhat similar to what was reported at [PIL installation / run
issue](http://stackoverflow.com/questions/10543581/pil-installation-run-
issue); however, it appears that in this case, JPEGs actually aren't working.
A similar problem is observed with PNGs.

It's not clear to me where in the process I've made a mistake, so any comments
would be greatly appreciated. Please let me know if additional information is
required, I'll endeavor to do by best to provide it.

Many thanks.


Answer: I have solved something similar but just for png support. I believe you can do
the same for jpeg support as well.

First I would recommend using Pillow, a fork of PIL. The solution I used is to
manually compile on my machine (win7 64 bit) the zlib library. And then
manualy compiling the Pillow Package. I edited the Setup.py like you did to
point at a directory where I put the zlib I just compiled.

I would suggest you manually compile the jpeg lib as well, and the zlib and
then compile Pillow again. Make sure to uninstall previous versions of
PIL/Pillow before doing it.

The link for my detailed answer of how to do it with zlib is:

<http://stackoverflow.com/a/17190972/2501083>

Hope this helps

