我正在运行Django 1.4
和PIL 1.1.7
在virtualenv
与pip
管理。每当我通过我的管理界面上传JPEG文件,我得到以下错误:Upload a valid image. The file you uploaded was either not an image or a corrupted image.
让Django识别PIL JPEG支持
正如很多Ubuntu的用户报告,在安装时,PIL erronously看着/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的仍 doesn不允许我上传除BMP文件以外的任何内容,这是本项目无法接受的。与第二个链接中的用户不同,我没有使用Apache,所以我的问题可能不相关。我怀疑Django仍在使用旧的PIL安装。问题是我不知道从哪里得到它。 ~/.virtualenvs/project/local/lib/python2.7/site-packages
中的文件对我来说似乎是最新的。有任何想法吗?
编辑1:另外请注意,我已经尝试注销并且管理员重新登录,以及在这个岗位上安装pillow
,如:Uploading a JPEG image via Django displays error
您是否尝试安装[Pillow](http://pypi.python.org/pypi/Pillow)而不是PIL?检查你的sys.path – jterrace 2012-07-27 16:47:43
你可以上传你的模型吗? – nicowernli 2012-07-27 16:53:52
@jterrace:是的。并且该安装还告诉我可以使用JPEG支持。 – novembrine 2012-07-27 16:55:10