views:

523

answers:

2

So I've finally successfully installed PIL (after many difficulties) on RHEL5 with Django (development version) and Python 2.6 installed at /opt/python2.6.

Running selftest.py shows that everything appears to be installed correctly:

$ python2.6 selftest.py 
57 tests passed.

I can upload .png files and .gif files without difficulties, but run into problems when trying to upload .jpg files using the ImageField: "Upload a valid image. The file you uploaded was either not an image or a corrupted image."

I saw this other question and ran the test to see if PIL would verify the image, and it did:

>>> from PIL import Image
>>> trial_image=Image.open("/tmp/jordanthecoder.jpg")
>>> trial_image.verify()
>>> 

What could be going on? Obviously, allowing JPEG is kind of important. I realize one option is to use a FileField instead and then check to make sure it is one of GIF, PNG, or JPEG, but I'd much rather use the built-in object.

In case this is helpful, here is the verbose display for the shell above:

$ python2.6 -v
Python 2.6.4 (r264:75706, Jan 15 2010, 14:42:33) 
[GCC 4.1.2 20080704 (Red Hat 4.1.2-46)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
dlopen("/opt/python2.6/lib/python2.6/lib-dynload/readline.so", 2);
import readline # dynamically loaded from /opt/python2.6/lib/python2.6/lib-dynload/readline.so
>>> from PIL import Image
import PIL # directory /opt/python2.6/lib/python2.6/site-packages/PIL
# /opt/python2.6/lib/python2.6/site-packages/PIL/__init__.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/__init__.py
import PIL # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/__init__.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/Image.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/Image.py
import PIL.Image # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/Image.pyc
# /opt/python2.6/lib/python2.6/lib-tk/FixTk.pyc matches /opt/python2.6/lib/python2.6/lib-tk/FixTk.py
import FixTk # precompiled from /opt/python2.6/lib/python2.6/lib-tk/FixTk.pyc
import ctypes # directory /opt/python2.6/lib/python2.6/ctypes
# /opt/python2.6/lib/python2.6/ctypes/__init__.pyc matches /opt/python2.6/lib/python2.6/ctypes/__init__.py
import ctypes # precompiled from /opt/python2.6/lib/python2.6/ctypes/__init__.pyc
dlopen("/opt/python2.6/lib/python2.6/lib-dynload/_ctypes.so", 2);
import _ctypes # dynamically loaded from /opt/python2.6/lib/python2.6/lib-dynload/_ctypes.so
# /opt/python2.6/lib/python2.6/struct.pyc matches /opt/python2.6/lib/python2.6/struct.py
import struct # precompiled from /opt/python2.6/lib/python2.6/struct.pyc
dlopen("/opt/python2.6/lib/python2.6/lib-dynload/_struct.so", 2);
import _struct # dynamically loaded from /opt/python2.6/lib/python2.6/lib-dynload/_struct.so
# /opt/python2.6/lib/python2.6/ctypes/_endian.pyc matches /opt/python2.6/lib/python2.6/ctypes/_endian.py
import ctypes._endian # precompiled from /opt/python2.6/lib/python2.6/ctypes/_endian.pyc
dlopen("/opt/python2.6/lib/python2.6/site-packages/PIL/_imaging.so", 2);
import PIL._imaging # dynamically loaded from /opt/python2.6/lib/python2.6/site-packages/PIL/_imaging.so
# /opt/python2.6/lib/python2.6/site-packages/PIL/ImageMode.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/ImageMode.py
import PIL.ImageMode # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/ImageMode.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/ImagePalette.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/ImagePalette.py
import PIL.ImagePalette # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/ImagePalette.pyc
dlopen("/opt/python2.6/lib/python2.6/lib-dynload/array.so", 2);
import array # dynamically loaded from /opt/python2.6/lib/python2.6/lib-dynload/array.so
# /opt/python2.6/lib/python2.6/string.pyc matches /opt/python2.6/lib/python2.6/string.py
import string # precompiled from /opt/python2.6/lib/python2.6/string.pyc
# /opt/python2.6/lib/python2.6/re.pyc matches /opt/python2.6/lib/python2.6/re.py
import re # precompiled from /opt/python2.6/lib/python2.6/re.pyc
# /opt/python2.6/lib/python2.6/sre_compile.pyc matches /opt/python2.6/lib/python2.6/sre_compile.py
import sre_compile # precompiled from /opt/python2.6/lib/python2.6/sre_compile.pyc
import _sre # builtin
# /opt/python2.6/lib/python2.6/sre_parse.pyc matches /opt/python2.6/lib/python2.6/sre_parse.py
import sre_parse # precompiled from /opt/python2.6/lib/python2.6/sre_parse.pyc
# /opt/python2.6/lib/python2.6/sre_constants.pyc matches /opt/python2.6/lib/python2.6/sre_constants.py
import sre_constants # precompiled from /opt/python2.6/lib/python2.6/sre_constants.pyc
dlopen("/opt/python2.6/lib/python2.6/lib-dynload/strop.so", 2);
import strop # dynamically loaded from /opt/python2.6/lib/python2.6/lib-dynload/strop.so
dlopen("/opt/python2.6/lib/python2.6/lib-dynload/operator.so", 2);
import operator # dynamically loaded from /opt/python2.6/lib/python2.6/lib-dynload/operator.so
>>> trial_image=Image.open("/tmp/jordanthecoder.jpg")
# /opt/python2.6/lib/python2.6/site-packages/PIL/BmpImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/BmpImagePlugin.py
import PIL.BmpImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/BmpImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/ImageFile.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/ImageFile.py
import PIL.ImageFile # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/ImageFile.pyc
# /opt/python2.6/lib/python2.6/traceback.pyc matches /opt/python2.6/lib/python2.6/traceback.py
import traceback # precompiled from /opt/python2.6/lib/python2.6/traceback.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/GifImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/GifImagePlugin.py
import PIL.GifImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/GifImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/JpegImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/JpegImagePlugin.py
import PIL.JpegImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/JpegImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/PpmImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/PpmImagePlugin.py
import PIL.PpmImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/PpmImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/PngImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/PngImagePlugin.py
import PIL.PngImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/PngImagePlugin.pyc
>>> trial_image.verify()
>>> fake_image = Image.open("/tmp/fakeimage.jpg") #text file ending in .jpg
# /opt/python2.6/lib/python2.6/site-packages/PIL/CurImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/CurImagePlugin.py
import PIL.CurImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/CurImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/ArgImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/ArgImagePlugin.py
import PIL.ArgImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/ArgImagePlugin.pyc
import marshal # builtin
# /opt/python2.6/lib/python2.6/site-packages/PIL/Hdf5StubImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/Hdf5StubImagePlugin.py
import PIL.Hdf5StubImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/Hdf5StubImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/MspImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/MspImagePlugin.py
import PIL.MspImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/MspImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/MicImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/MicImagePlugin.py
import PIL.MicImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/MicImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/TiffImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/TiffImagePlugin.py
import PIL.TiffImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/TiffImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/OleFileIO.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/OleFileIO.py
import PIL.OleFileIO # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/OleFileIO.pyc
# /opt/python2.6/lib/python2.6/StringIO.pyc matches /opt/python2.6/lib/python2.6/StringIO.py
import StringIO # precompiled from /opt/python2.6/lib/python2.6/StringIO.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/FitsStubImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/FitsStubImagePlugin.py
import PIL.FitsStubImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/FitsStubImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/MpegImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/MpegImagePlugin.py
import PIL.MpegImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/MpegImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/PixarImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/PixarImagePlugin.py
import PIL.PixarImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/PixarImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/DcxImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/DcxImagePlugin.py
import PIL.DcxImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/DcxImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/PcxImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/PcxImagePlugin.py
import PIL.PcxImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/PcxImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/WmfImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/WmfImagePlugin.py
import PIL.WmfImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/WmfImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/XVThumbImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/XVThumbImagePlugin.py
import PIL.XVThumbImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/XVThumbImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/XbmImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/XbmImagePlugin.py
import PIL.XbmImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/XbmImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/ImtImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/ImtImagePlugin.py
import PIL.ImtImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/ImtImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/IptcImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/IptcImagePlugin.py
import PIL.IptcImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/IptcImagePlugin.pyc
# /opt/python2.6/lib/python2.6/tempfile.pyc matches /opt/python2.6/lib/python2.6/tempfile.py
import tempfile # precompiled from /opt/python2.6/lib/python2.6/tempfile.pyc
# /opt/python2.6/lib/python2.6/random.pyc matches /opt/python2.6/lib/python2.6/random.py
import random # precompiled from /opt/python2.6/lib/python2.6/random.pyc
# /opt/python2.6/lib/python2.6/__future__.pyc matches /opt/python2.6/lib/python2.6/__future__.py
import __future__ # precompiled from /opt/python2.6/lib/python2.6/__future__.pyc
dlopen("/opt/python2.6/lib/python2.6/lib-dynload/math.so", 2);
import math # dynamically loaded from /opt/python2.6/lib/python2.6/lib-dynload/math.so
dlopen("/opt/python2.6/lib/python2.6/lib-dynload/binascii.so", 2);
import binascii # dynamically loaded from /opt/python2.6/lib/python2.6/lib-dynload/binascii.so
dlopen("/opt/python2.6/lib/python2.6/lib-dynload/_random.so", 2);
import _random # dynamically loaded from /opt/python2.6/lib/python2.6/lib-dynload/_random.so
dlopen("/opt/python2.6/lib/python2.6/lib-dynload/cStringIO.so", 2);
import cStringIO # dynamically loaded from /opt/python2.6/lib/python2.6/lib-dynload/cStringIO.so
dlopen("/opt/python2.6/lib/python2.6/lib-dynload/fcntl.so", 2);
import fcntl # dynamically loaded from /opt/python2.6/lib/python2.6/lib-dynload/fcntl.so
import thread # builtin
# /opt/python2.6/lib/python2.6/site-packages/PIL/GribStubImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/GribStubImagePlugin.py
import PIL.GribStubImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/GribStubImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/TgaImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/TgaImagePlugin.py
import PIL.TgaImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/TgaImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/BufrStubImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/BufrStubImagePlugin.py
import PIL.BufrStubImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/BufrStubImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/FpxImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/FpxImagePlugin.py
import PIL.FpxImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/FpxImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/SgiImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/SgiImagePlugin.py
import PIL.SgiImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/SgiImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/FliImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/FliImagePlugin.py
import PIL.FliImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/FliImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/PcdImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/PcdImagePlugin.py
import PIL.PcdImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/PcdImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/PalmImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/PalmImagePlugin.py
import PIL.PalmImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/PalmImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/XpmImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/XpmImagePlugin.py
import PIL.XpmImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/XpmImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/ImImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/ImImagePlugin.py
import PIL.ImImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/ImImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/SunImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/SunImagePlugin.py
import PIL.SunImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/SunImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/IcnsImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/IcnsImagePlugin.py
import PIL.IcnsImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/IcnsImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/McIdasImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/McIdasImagePlugin.py
import PIL.McIdasImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/McIdasImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/PdfImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/PdfImagePlugin.py
import PIL.PdfImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/PdfImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/GbrImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/GbrImagePlugin.py
import PIL.GbrImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/GbrImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/EpsImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/EpsImagePlugin.py
import PIL.EpsImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/EpsImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/IcoImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/IcoImagePlugin.py
import PIL.IcoImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/IcoImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/SpiderImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/SpiderImagePlugin.py
import PIL.SpiderImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/SpiderImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/PsdImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/PsdImagePlugin.py
import PIL.PsdImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/PsdImagePlugin.pyc
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/python2.6/lib/python2.6/site-packages/PIL/Image.py", line 1916, in open
    raise IOError("cannot identify image file")
IOError: cannot identify image file

UPDATE

Here is the output for $ python manage.py shell (skipping initial import statements):

Python 2.6.4 (r264:75706, Jan 15 2010, 14:42:33) 
[GCC 4.1.2 20080704 (Red Hat 4.1.2-46)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from PIL import Image
import PIL # directory /opt/python2.6/lib/python2.6/site-packages/PIL
# /opt/python2.6/lib/python2.6/site-packages/PIL/__init__.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/__init__.py
import PIL # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/__init__.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/Image.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/Image.py
import PIL.Image # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/Image.pyc
# /opt/python2.6/lib/python2.6/lib-tk/FixTk.pyc matches /opt/python2.6/lib/python2.6/lib-tk/FixTk.py
import FixTk # precompiled from /opt/python2.6/lib/python2.6/lib-tk/FixTk.pyc
import ctypes # directory /opt/python2.6/lib/python2.6/ctypes
# /opt/python2.6/lib/python2.6/ctypes/__init__.pyc matches /opt/python2.6/lib/python2.6/ctypes/__init__.py
import ctypes # precompiled from /opt/python2.6/lib/python2.6/ctypes/__init__.pyc
dlopen("/opt/python2.6/lib/python2.6/lib-dynload/_ctypes.so", 2);
import _ctypes # dynamically loaded from /opt/python2.6/lib/python2.6/lib-dynload/_ctypes.so
# /opt/python2.6/lib/python2.6/ctypes/_endian.pyc matches /opt/python2.6/lib/python2.6/ctypes/_endian.py
import ctypes._endian # precompiled from /opt/python2.6/lib/python2.6/ctypes/_endian.pyc
dlopen("/opt/python2.6/lib/python2.6/site-packages/PIL/_imaging.so", 2);
import PIL._imaging # dynamically loaded from /opt/python2.6/lib/python2.6/site-packages/PIL/_imaging.so
# /opt/python2.6/lib/python2.6/site-packages/PIL/ImageMode.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/ImageMode.py
import PIL.ImageMode # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/ImageMode.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/ImagePalette.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/ImagePalette.py
import PIL.ImagePalette # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/ImagePalette.pyc
>>> trial_image=Image.open("/tmp/jordanthecoder.jpg")
# /opt/python2.6/lib/python2.6/site-packages/PIL/BmpImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/BmpImagePlugin.py
import PIL.BmpImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/BmpImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/ImageFile.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/ImageFile.py
import PIL.ImageFile # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/ImageFile.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/GifImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/GifImagePlugin.py
import PIL.GifImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/GifImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/JpegImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/JpegImagePlugin.py
import PIL.JpegImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/JpegImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/PpmImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/PpmImagePlugin.py
import PIL.PpmImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/PpmImagePlugin.pyc
# /opt/python2.6/lib/python2.6/site-packages/PIL/PngImagePlugin.pyc matches /opt/python2.6/lib/python2.6/site-packages/PIL/PngImagePlugin.py
import PIL.PngImagePlugin # precompiled from /opt/python2.6/lib/python2.6/site-packages/PIL/PngImagePlugin.pyc
>>> trial_image.verify()
>>> 

UPDATE #2:

Okay, so I decided to bypass ImageField altogether and just see what PIL does on its own. This is the code in question (in my views.py file):

def test_image(request):
    i = Image.open("/tmp/jordanthecoder.jpg")
    t = i.verify()
    return HttpResponse("Image is "+repr(i.info))

This is the webpage output:

Image is {'jfif_version': (1, 1), 'jfif': 257, 'jfif_unit': 1, 'jfif_density': (72, 72), 'dpi': (72, 72)}

UPDATE #3

So, these are the modules and paths for the two different systems. I'm not exactly sure why they're so different and what I can do to change the behavior of the web version.

They actually were using different JSON modules, pretty sure that that makes no difference. Other than that, here are the different modules. Assume these modules are all somewhere in /opt/python2.6/...

Only in the web version:

django.contrib.sessions.*, django.core.email, django.core.handlers.*, django.core.mail, django.core.mimetypes, django.core.os, django.core.random, django.core.smtplib, django.core.socket, django.core.time, django.middleware.*, email.*, encodings.ascii, hmac, mimetypes, mod_wsgi, smtplib, uu

Only in the shell version:

code, codeop, django.core.management.*, readline, rlcompleter, settings, user

Thanks

** UPDATE #4 **

Looks like the problem is that apache is using the incorrect libjpeg.so, whereas python is using the right one. I've created a more generalized version of the question that isn't specific to Django.

A: 

My impression of the PIL JPEG problem is that it's almost always a system configuration problem.

You built and configured PIL and tested with that version and it worked. So, my guess is that Django is pulling in a different PIL, probably one built without JPEG support or that can't find libjpeg.

You can confirm this by running your test again but using python -v manage.py shell instead of running python2.6 directly. You need to be careful here though and make sure your python executable and PYTHONPATH exactly match what is loaded by your web server.

Van Gale
Since this is a RHEL system I can't really use python directly since it's an older version. I'm using mod_wsgi and I believe it's running python 2.6 anyway (otherwise, pretty sure nothing in Django would run!)Is there any way to output which version of PIL is being used on the webpage itself?
Jordan Reiter
Nevermind, looks like python now correctly points to python2.6 anyway.I'll put the output for that up as well.
Jordan Reiter
Okay, after looking over your answer again I realize what you were saying -- you meant to see what came up when calling the Django manage.py shell. I did that, looks like verify works fine as well. Very strange; looks like it *only* happens during a web request.
Jordan Reiter
Running manage.py from your login shell can still operate differently from web requests because it's still inheriting from your interactive shell environment. You need to make sure your the python exe and PYTHONPATH are the same in your mod_wsgi environment. Getting PIL version # isn't enough either because system PIL could be same version but built without JPEG support.
Van Gale
Is there a way to output all of this directly on the page, or a way to run the Image.verify() with debug output somehow?
Jordan Reiter
See edit on answer
Van Gale
Okay, python paths are now identical (although modules loaded are not -- but no difference in PIL modules). Still getting the error! Very frustrating.
Jordan Reiter
+2  A: 

See possible answer in:

http://stackoverflow.com/questions/2173103/is-it-possible-to-control-which-libraries-apache-uses

Referencing here so can still get bounty if awarded. :-)

Graham Dumpleton
So noted. See my comments in the other post, thanks.
Jordan Reiter
Woah. Looks like you are about to win the giant kielbasa. Disabling PHP did the trick. Now I just need to figure out how to get fastcgi installed on RHEL and I'm good to go.
Jordan Reiter
A WINNER IS YOU.
Jordan Reiter