PIL编码器jpeg不可用 [英] PIL encoder jpeg not available

查看:95
本文介绍了PIL编码器jpeg不可用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
pip install PIL -E TICKETS-1-No JPEG/PNG支持

Possible Duplicate:
pip install PIL -E TICKETS-1 - No JPEG/PNG support

我正在处理图片裁剪器,但是我无法进行表单验证.上传GIF图片时,该表单已通过验证,但是我尝试使用的其他任何格式都会引发以下异常:

I'm working on a picture cropper, and I'm having trouble with my form validation. The form is validated when uploading a GIF picture, but any other format I try raises the following exception:

Upload a valid image. The file you uploaded was either not an image or a corrupted image.

表格

<form enctype="multipart/form-data" method="post" action="/pic/">{% csrf_token %}
    {{ form.as_p }}
    <p><input type="submit" value="View uploaded image"></p>
    <input type="hidden" name="stage" value="crop">
</form>

查看

if request.method == 'POST':
        form = ProfilePicForm(request.POST, request.FILES)
        if form.is_valid():
            *do stuff*
        else:
            logger.debug('Form errors == [%s]' % form.errors)

在安装PIL(使用easy_install)之前,我已经安装了libjpeg-dev(使用apt-get).起初,我认为这可能是由于libjpeg-dev或PIL的安装不正确造成的,但是对于其他格式(如png),问题是否还会继续存在?实际上,png图像也确实会出现此问题.我没有遇到jpeg解码器问题,所以我认为不是这样,但是我不确定.另外,我正在使用django开发服务器.

I have installed libjpeg-dev(using apt-get) before installing PIL(using easy_install). At first, I thought this might be due to an incorrect installation of either libjpeg-dev or PIL, but would the problem persists for other formats like png? This problem does in fact occur for png images as well. I'm not getting a jpeg decoder problem, so I'm thinking it's not that, but I'm not sure. Also, I'm using the django development server.

我决定尝试重新安装PIL.我删除了我的PIL安装文件夹 /usr/local/lib/python2.7/dist-packages/PIL 和我的PIL.pth文件(在同一dist-packages文件夹中).我使用sudo python setup.py install运行setup.py脚本.然后,我运行了selftest.py脚本,它在第一次测试中失败了:

I decided to try a reinstall of PIL. I deleted my PIL install folder /usr/local/lib/python2.7/dist-packages/PIL and my PIL.pth file (in the same dist-packages folder). I ran the setup.py script using sudo python setup.py install. I then ran the selftest.py script, and it fails on the first test:

--------------------------------------------------------------------
PIL 1.1.7 TEST SUMMARY 
--------------------------------------------------------------------
Python modules loaded from ./PIL
Binary modules loaded from ./PIL
--------------------------------------------------------------------
--- PIL CORE support ok
*** TKINTER support not installed
*** JPEG support not installed
*** ZLIB (PNG/ZIP) support not installed
*** FREETYPE2 support not installed
--- LITTLECMS support ok
--------------------------------------------------------------------
Running selftest:
*****************************************************************
Failure in example:
try:
 _info(Image.open(os.path.join(ROOT, "Images/lena.jpg")))
except IOError, v:
 print v
from line #24 of selftest.testimage
Expected: ('JPEG', 'RGB', (128, 128))
Got: decoder jpeg not available
1 items had failures:
   1 of  57 in selftest.testimage
***Test Failed*** 1 failures.
*** 1 tests of 57 failed.

我不确定如何使PIL与上面列出的不受支持的模块一起使用.我可以验证是否具有zlib1g-dev,libfreetype6-dev,liblcms1-dev和libjpeg62-dev,以及库本身已安装在系统上,因为当我尝试使用apt-get安装它们时,它说我已经拥有最新版本

I'm not sure how to get PIL to work with the unsupported modules listed above. I can verify that I have zlib1g-dev, libfreetype6-dev, liblcms1-dev and libjpeg62-dev, and the libraries themselves installed on my system because when I try to install them with apt-get, it says I already have the latest version.

推荐答案

尝试从源代码下载PIL,然后编辑setup.py,并添加以下行:

Try downloading PIL from source, then edit setup.py adding this line:

add_directory(library_dirs, "/usr/lib/i386-linux-gnu")

在此行之前(214):

before this line (214):

add_directory(library_dirs, "/usr/lib")

然后

sudo python setup.py install

现在应该可以正常工作

这篇关于PIL编码器jpeg不可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆