Correctly installing PIL with JPEG
So today I tried to download and start playing around with the Python Imaging Library, and I realized that it's not as easy as downloading it.
I used a simple script to open a .jpeg image:
import sys from PIL import Image PIL_Version = Image.VERSION img_filename = 'some_filepath_here' im = Image.open(img_filename) im.show() And much to my dismay, it didn't run, giving me an IOError. IOError: decoder jpeg not available Basically what this meant was that PIL natively supports png but on a Mac atleast, you need to separately install a module for handling .jpeg images. I'd suggest any PIL user to do that, after all how are you going to escape .jpegs in image processing? Here's a step-by-step explanation of how I resolved the issue. 1. Uninstall already-existing PIL sudo rm -rf /usr/lib/python2.7/site-packages/PIL sudo rm ~/Imaging-1.1.7 This is what worked for me, if there are other ways you would prefer of uninstalling PIL, please use them. Make sure it's all gone before proceeding to the next steps. 2. Get the newest version of the JPEG library here: http://www.ijg.org/files/jpegsrc.v8.tar.gz 3. Execute the following statements on your command line prompt, after cd ing into the directory you installed the library in. $ tar zxvf jpegsrc.v7.tar.gz $ cd jpeg-7 $ ./configure --enable-shared --enable-static $ make $ sudo make install 4. Download PIL from here: http://effbot.org/downloads/Imaging-1.1.7.tar.gz If you have the tar ball already and haven't deleted that, it's alright to use the same one. 5. Execute the following statements on your command line prompt, after cd ing into the directory you installed the library in. $ tar zxvf Imaging-1.1.6.tar.gz $ cd Imaging-1.1.6 6. Edit setup.py, set JPEG_ROOT = libinclude("/usr/local") 7. Build the setup.py again by executing the following: $ python setup.py build 8. Install the newly built library: $ sudo python setup.py install --optimize=1 9. Restart IDLE/ your development environment This works like a charm! If someone has issues with this, please let me know! PS: Posts that helped me: http://simonwilder.wordpress.com/2009/06/17/fixing-pil-ioerror-decoder-jpeg-not-available/ https://groups.google.com/forum/?fromgroups#!topic/google-appengine-python/_v3NjQL77pQ