PIL编码器jpeg不可用

Nat*_*nes 5 python django libjpeg python-imaging-library

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

我正在处理图片裁剪器,我的表单验证有问题.上传GIF图片时验证表单,但我尝试的任何其他格式都会引发以下异常:

Upload a valid image. The file you uploaded was either not an image or a corrupted image.
Run Code Online (Sandbox Code Playgroud)

形成

<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>
Run Code Online (Sandbox Code Playgroud)

视图

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

我在安装PIL之前安装了libjpeg-dev(使用apt-get)(使用easy_install).起初,我认为这可能是由于libjpeg-dev或PIL的安装不正确,但png等其他格式问题是否仍然存在?事实上,对于png图像也会出现此问题.我没有得到一个jpeg解码器问题,所以我认为不是那个,但我不确定.另外,我正在使用django开发服务器.


更新

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

--------------------------------------------------------------------
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.
Run Code Online (Sandbox Code Playgroud)

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

Jul*_*ian 11

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

add_directory(library_dirs, "/usr/lib/i386-linux-gnu")
Run Code Online (Sandbox Code Playgroud)

在这一行之前(214):

add_directory(library_dirs, "/usr/lib")
Run Code Online (Sandbox Code Playgroud)

然后

sudo python setup.py install
Run Code Online (Sandbox Code Playgroud)

它现在应该工作

  • 我以不同方式修改了`setup.py`,但它也有效.我将`JPEG_ROOT = None`更改为`JPEG_ROOT ="/ usr/lib/x86_64-linux-gnu"`然后运行`setup.py`并且它有效. (7认同)
  • for bluehost add add_directory(library_dirs,"/ usr/lib64") (5认同)