今天在Python运行环境的服务器弄一个有关图像处理的程序时报这样的错:

1 NameError: global name 'Image' is not defined

import Image 了下,发现原来 Python 并没有自带图像处理库,需要独立安装……查了下,Python常用的图像处理库叫PIL,可以使用 pip 安装,不错~于是在 用virtualenv 里敲入 pip install PIL。

安装很快完成,于是愉悦地刷新,等待程序的通过,结果又报错:

1 IOError: decoder jpeg not available

Google了下,发现通过 pip 安装的 PIL 不会安装 jpeg 的解码器……检查了下安装日志,也有这样的说明:

01 --------------------------------------------------------------------
02 PIL 1.1.7 SETUP SUMMARY
03 --------------------------------------------------------------------
04 version       1.1.7
05 platform      linux2 2.7.5 (default, Sep 18 201309:53:07)
06               [GCC 4.1.2 20080704 (Red Hat 4.1.2-54)]
07 --------------------------------------------------------------------
08 *** TKINTER support not available
09 *** JPEG support not available
10 *** ZLIB (PNG/ZIP) support not available
11 *** FREETYPE2 support not available
12 *** LITTLECMS support not available
13 --------------------------------------------------------------------
14 To add a missing option, make sure you have the required
15 library, and set the corresponding ROOT variable in the
16 setup.py script.

JPEG support not available…… jpg都不支持,这是闹哪样……

于是只得手动安装了:

1 wget http://effbot.org/downloads/Imaging-1.1.7.tar.gz
2 tar xvfz Imaging-1.1.7.tar.gz

下载并解压成功之后,到解压目录,找到 Imaging-1.1.7/setup.py 这个文件,修改下面几行代码(默认TCL_ROOT的设置为NONE,这里要传到系统库的路径才行):

1 TCL_ROOT = "/usr/lib64/"
2 JPEG_ROOT = "/usr/lib64/"
3 ZLIB_ROOT = "/usr/lib64/"
4 TIFF_ROOT = "/usr/lib64/"
5 FREETYPE_ROOT = "/usr/lib64/"
6 LCMS_ROOT = "/usr/lib64/"

再进行安装前的检查:

1 python /root/nowamagic_venv/Imaging-1.1.7/setup.py build_ext -i

检查没问题,可以执行安装了:

1 python /root/nowamagic_venv/Imaging-1.1.7/setup.py install

安装成功:

01 --------------------------------------------------------------------
02 PIL 1.1.7 SETUP SUMMARY
03 --------------------------------------------------------------------
04 version       1.1.7
05 platform      linux2 2.7.5 (default, Sep 18 201309:53:07)
06               [GCC 4.1.2 20080704 (Red Hat 4.1.2-54)]
07 --------------------------------------------------------------------
08 *** TKINTER support not available
09 --- JPEG support available
10 --- ZLIB (PNG/ZIP) support available
11 --- FREETYPE2 support available
12 *** LITTLECMS support not available
13 --------------------------------------------------------------------

现在 jpg 已经被支持了,程序也执行成功,这里简单记录一下过程,方便后来者。顺便附带测试程序,用 Tornado 上传图片并生成缩略图:

01 import time
02 import tempfile
03 import Image
04  
05 class AsciiImageProcessHandler(tornado.web.RequestHandler):
06     def post(self):
07  
08         if self.request.files:
09             for in self.request.files['image']:
10                 rawname = f['filename']
11                 dstname =str(int(time.time()))+'.'+rawname.split('.').pop()
12                 thbname = "thumb_"+dstname
13  
14                 self.write( dstname )
15  
16                 tf = tempfile.NamedTemporaryFile()
17                 tf.write(f['body'])
18                 tf.seek(0)
19  
20                 # create normal file
21                 # img = Image.open(src)
22                 img = Image.open(tf.name)
23                 img.thumbnail((920,920),resample=1)
24                 img.save("./static/upload/asciiimg/"+dstname)
25  
26                 # create thumb file
27                 img.thumbnail((100,100),resample=1)
28                 img.save("./static/upload/asciiimg_tn/"+thbname)
29   
30                 tf.close()

python PIL except: IOError: decoder jpeg not available的更多相关文章

  1. ubuntu14.04 安装PIL库出现OError: decoder jpeg not available 的解决方案

    出现 OError: decoder jpeg not available 的原因是,没有装JPEG的库,同时要支持png图片的话还要装 ZLIB.FREETYPE2.LITTLECMS的库文件. 先 ...

  2. Python PIL : IOError: decoder jpeg not available

    The first thing I check when I got this error was to check if libjpeg was installed. Lets try this s ...

  3. exceptions.IOError: decoder jpeg not available

    1.确保安装PIL所需的系统库 yum -y install zlib yum -y install  zlib-devel yum -y install libjpeg yum -y install ...

  4. Python 读文件:IOError: [Errno 0] Error

    Windows系统下,这种情况发生在读取文件,再写入过程中出现. 原因是读完文件后python不知道当前文件位置在哪里. 方法一是:在关闭文件前只做读或者写一种操作. 方法二是:在写入文件前使用fil ...

  5. Python,PIL压缩裁剪图片

    自己写了用来压缩 DC 照片的,批量处理整目录文件,非常方便.需要安装 PIL #!/usr/bin/env python import Image import os import os.path ...

  6. Python图像处理库:PIL中Image,ImageDraw等基本模块介绍

    Python图像处理库:PIL中Image,ImageDraw等基本模块介绍 标签: 图像处理PILPYTHON 2016-08-19 10:58 461人阅读 评论(0) 收藏 举报  分类: 其他 ...

  7. Python:IOError: image file is truncated 的解决办法

    代码如下: #coding:utf-8 from PIL import Image import pytesseract def test(): im = Image.open(r"pic. ...

  8. Python图像处理库:Pillow 初级教程

    Python图像处理库:Pillow 初级教程 2014-09-14 翻译 http://pillow.readthedocs.org/en/latest/handbook/tutorial.html ...

  9. python PIL 图像处理操作

    python PIL 图像处理 # 导入Image库 import Image # 读取图片 im = Image.open("1234.jpg") # 显示图片 im.show( ...

随机推荐

  1. hdu-5009-Paint Pearls-dp

    由题意我们能够知道,花费最多为n. 所以单次最多涂掉sqrt(n)种颜色. dp[i]:涂到第i个位置.之前的花费最少为多少. biao[i][j]:在第i个位置,往前涂j-1种颜色,涂到哪个位置. ...

  2. 搜索框中“请输入搜索keyword”

    $(function(){    $("#ctl00_txtKey").val("请输入搜索keyword").addClass("search&qu ...

  3. iOS-UIResponse之事件响应链及其事件传递

    UIResponse之事件响应链及其事件传递 我们的App与用户进行交互,基本上是依赖于各种各样的事件.一个视图是一个事件响应者,可以处理点击等事件,而这些事件就是在UIResponder类中定义的. ...

  4. WCF 用netTcpbinding,basicHttpBinding 传输大文件

    问题:WCF如何传输大文件 方案:主要有几种绑定方式netTcpbinding,basicHttpBinding,wsHttpbinding,设置相关的传输max消息选项,服务端和客户端都要设置,tr ...

  5. Canvas模糊化处理图片、毛玻璃处理图片之stackblur.js

    Canvas实现毛玻璃效果解决方式1:使用stackblur.js 在Android系统中实现图片的毛玻璃效果比较好用的类库是:Android StackBlur 官方Git地址:https://gi ...

  6. org.springframework.beans.factory.BeanCreationException: 求教育!

    2014-11-26 14:05:56 [org.springframework.web.context.support.XmlWebApplicationContext]-[WARN] Except ...

  7. Axis,axis2,Xfire以及cxf对比 (转)

    Axis,axis2,Xfire以及cxf对比   http://ws.apache.org/axis/ http://axis.apache.org/axis2/java/core/ http:// ...

  8. linux常用命令之tail

    从指定点开始将文件写到标准输出.使用tail命令的-f选项可以方便的查阅正在改变的日志文件,tail -f filename会把filename里最尾部的内容显示在屏幕上,并且不但刷新,使你看到最新的 ...

  9. undefined与null的区别(待修整)

    没有实体的对象称为空对象.只用对象的引用,而不存在引用的实体对象 就叫做空对象 在常见的强类型语言中,通常有一个表示"空"的值,比如NULL.但是在Javascript中,空(或者 ...

  10. I/O多路转接之select

    系统提供select函数来实现多路复⽤用输入/输出模型.select系统调用是用来让我们的程序监视 多个文件句柄的状态变化的.程序会停在select这里等待,直到被监视的文件句柄有一个或 多个发生了状 ...