【发布时间】:2012-07-26 09:16:14
【问题描述】:
我正在使用pip 管理的virtualenv 中运行Django 1.4 和PIL 1.1.7。每当我通过管理界面上传 JPEG 文件时,都会收到以下错误:Upload a valid image. The file you uploaded was either not an image or a corrupted image.
正如许多 Ubuntu 用户所报告的那样,在安装时,PIL 错误地在 /usr/lib/ 中查找 libjpeg,而它的真实位置在 /usr/lib/i386-linux-gnu/。已经处理好了;我遵循了这些帖子中的答案:
Why can't I upload jpg files to my Django app via admin/?
现在安装的最终输出如下:
PIL 1.1.7 SETUP SUMMARY
--------------------------------------------------------------------
version 1.1.7
platform linux2 2.7.3 (default, Apr 20 2012, 22:44:07)
[GCC 4.6.3]
--------------------------------------------------------------------
--- TKINTER support available
--- JPEG support available
--- ZLIB (PNG/ZIP) support available
--- FREETYPE2 support 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.
changing mode of build/scripts-2.7/pilfile.py from 644 to 755
changing mode of build/scripts-2.7/pilfont.py from 644 to 755
changing mode of build/scripts-2.7/pilconvert.py from 644 to 755
changing mode of build/scripts-2.7/pilprint.py from 644 to 755
changing mode of build/scripts-2.7/pildriver.py from 644 to 755
changing mode of /usr/local/bin/pilfile.py to 755
changing mode of /usr/local/bin/pilfont.py to 755
changing mode of /usr/local/bin/pilconvert.py to 755
changing mode of /usr/local/bin/pilprint.py to 755
changing mode of /usr/local/bin/pildriver.py to 755
Successfully installed PIL
但是,Django 仍然 不允许我上传 BMP 文件以外的任何内容,这对于该项目是不可接受的。与第二个链接中的用户不同,我没有使用 Apache,所以我的问题可能不相关。我怀疑 Django 仍在使用旧的 PIL 安装。问题是我不知道它是从哪里得到的。 ~/.virtualenvs/project/local/lib/python2.7/site-packages 中的文件对我来说似乎是最新的。有什么想法吗?
编辑 1:还请注意,我已尝试注销并重新登录管理员,以及安装 pillow,如在这篇文章中:Uploading a JPEG image via Django displays error
【问题讨论】:
-
您是否尝试安装 Pillow 而不是 PIL?检查你的 sys.path
-
@jterrace:是的。该安装还告诉我 JPEG 支持可用。
-
@nicowernli:当然。我将在编辑中添加它。
-
运行
manage.py shell并尝试类似import Image; im = Image.open("file.jpg"); im.show()看看它是否有效 -
您的系统中可能有多个 PIL。试试这个
>>> import Image>>> Image.__file__'/usr/lib/python2.6/site-packages/PIL/Image.pyc',看看你要导入哪个。
标签: python django python-imaging-library virtualenv libjpeg