Ошибка неверного образа в Django, но PIL установлен и проходит все тесты - PullRequest
3 голосов
/ 21 января 2010

Итак, я, наконец, успешно установил PIL (после многих трудностей) на RHEL5 с Django (версия для разработки) и Python 2.6, установленным в /opt/python2.6.

Запуск selftest.py показывает, что все появляетсядля правильной установки:

$ python2.6 selftest.py 
57 tests passed.

Я могу загрузить файлы .png и .gif без проблем, но у меня возникают проблемы при попытке загрузить файлы .jpg с помощью ImageField: «Загрузить действительное изображение. ФайлВы загрузили не изображение или не поврежденное изображение. "

Я видел этот другой вопрос и запустил тест, чтобы проверить, будет ли PIL проверять изображение, и он это сделал:

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

Что может происходить?Очевидно, что разрешение JPEG является своего рода важным.Я понимаю, что один из вариантов - использовать вместо этого FileField, а затем убедиться, что это один из файлов GIF, PNG или JPEG, но я бы предпочел использовать встроенный объект.

В случае, если этополезно, вот подробное отображение оболочки выше:

$ 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

Вот вывод для оболочки $ python manage.py (пропуская начальные операторы импорта):

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()
>>> 

ОБНОВЛЕНИЕ № 2:

Хорошо, поэтому я решил вообще обойти ImageField и просто посмотреть, что делает PIL самостоятельно.Это код вопроса (в моем файле views.py):

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

Это вывод веб-страницы:

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

UPDATE # 3

Итак,это модули и пути для двух разных систем.Я не совсем уверен, почему они такие разные и что я могу сделать, чтобы изменить поведение веб-версии.

Они на самом деле использовали разные модули JSON, почти уверен, что это не имеет значения.Помимо этого, здесь есть разные модули.Предположим, что все эти модули находятся где-то в /opt/python2.6/...

Только в веб-версии:

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

Только в версии оболочки:

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

Спасибо

** ОБНОВЛЕНИЕ # 4 **

Похоже, проблема в том, что apache использует неправильный libjpeg.so, тогда как python использует правильный.Я создал более обобщенную версию вопроса, не относящуюся к Django.

Ответы [ 2 ]

2 голосов
/ 03 февраля 2010

См. Возможный ответ в:

Можно ли контролировать, какие библиотеки использует Apache?

Ссылка здесь, чтобы получить награду. : -)

0 голосов
/ 21 января 2010

У меня сложилось впечатление, что проблема PIL JPEG заключается в том, что это почти всегда проблема конфигурации системы.

Вы создали и настроили PIL и протестировали с этой версией, и это сработало. Итак, я предполагаю, что Django использует другой PIL, возможно, построенный без поддержки JPEG или не может найти libjpeg.

Вы можете подтвердить это, выполнив тест снова, но используя python -v manage.py shell вместо прямого запуска python2.6. Здесь вы должны быть осторожны и убедиться, что ваш исполняемый файл python и PYTHONPATH точно соответствуют тому, что загружено вашим веб-сервером.

...