今天在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 |
-------------------------------------------------------------------- |
05 |
platform linux2 2.7.5 (default, Sep 18 2013, 09: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 |
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 |
-------------------------------------------------------------------- |
05 |
platform linux2 2.7.5 (default, Sep 18 2013, 09: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 上传图片并生成缩略图:
05 |
class AsciiImageProcessHandler(tornado.web.RequestHandler): |
08 |
if self.request.files: |
09 |
for f in self.request.files['image']: |
10 |
rawname = f['filename'] |
11 |
dstname =str(int(time.time()))+'.'+rawname.split('.').pop() |
12 |
thbname = "thumb_"+dstname |
16 |
tf = tempfile.NamedTemporaryFile() |
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) |
27 |
img.thumbnail((100,100),resample=1) |
28 |
img.save("./static/upload/asciiimg_tn/"+thbname) |
- ubuntu14.04 安装PIL库出现OError: decoder jpeg not available 的解决方案
出现 OError: decoder jpeg not available 的原因是,没有装JPEG的库,同时要支持png图片的话还要装 ZLIB.FREETYPE2.LITTLECMS的库文件. 先 ...
- 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 ...
- exceptions.IOError: decoder jpeg not available
1.确保安装PIL所需的系统库 yum -y install zlib yum -y install zlib-devel yum -y install libjpeg yum -y install ...
- Python 读文件:IOError: [Errno 0] Error
Windows系统下,这种情况发生在读取文件,再写入过程中出现. 原因是读完文件后python不知道当前文件位置在哪里. 方法一是:在关闭文件前只做读或者写一种操作. 方法二是:在写入文件前使用fil ...
- Python,PIL压缩裁剪图片
自己写了用来压缩 DC 照片的,批量处理整目录文件,非常方便.需要安装 PIL #!/usr/bin/env python import Image import os import os.path ...
- Python图像处理库:PIL中Image,ImageDraw等基本模块介绍
Python图像处理库:PIL中Image,ImageDraw等基本模块介绍 标签: 图像处理PILPYTHON 2016-08-19 10:58 461人阅读 评论(0) 收藏 举报 分类: 其他 ...
- Python:IOError: image file is truncated 的解决办法
代码如下: #coding:utf-8 from PIL import Image import pytesseract def test(): im = Image.open(r"pic. ...
- Python图像处理库:Pillow 初级教程
Python图像处理库:Pillow 初级教程 2014-09-14 翻译 http://pillow.readthedocs.org/en/latest/handbook/tutorial.html ...
- python PIL 图像处理操作
python PIL 图像处理 # 导入Image库 import Image # 读取图片 im = Image.open("1234.jpg") # 显示图片 im.show( ...
随机推荐
- Java keyword具体解释
訪问控制修饰符号 1) private 私有的 private keyword是訪问控制修饰符,能够应用于类.方法或字段(在类中声明的变量). 仅仅能在声明 private(内部)类.方 ...
- [Flux] 2. Overview and Dispatchers
Flux has four major components: Stores, Dispatchers, Views, and Actions. These components interact l ...
- POCISO-採购创建内部订单(R12.2.3)
採购创建内部订单(R12.2.3) --US Program:Create Internal Orders Short Name:POCISO Application:Purchasing Ex ...
- Android 颜色渲染(二) 颜色区域划分原理与实现思路
版权声明:本文为博主原创文章,未经博主允许不得转载. 上一篇讲到颜色选择器,该demo不能选择黑白或者具体区间颜色,这是为什么呢,还是要从原理部分讲起,首先看一下两张图: 图1 ...
- Linux 常用命令使用方法大搜刮(转)
1.# 表示权限用户(如:root),$ 表示普通用户 开机提示:Login:输入用户名 password:输入口令 用户是系统注册用户成功登陆后,可以进入相应的用户环境. 退出当前shel ...
- LINUX内核调度器+linux 内存
http://www.cnblogs.com/tolimit/p/4303052.html
- 初步掌握MapReduce的架构及原理
目录 1.MapReduce定义 2.MapReduce来源 3.MapReduce特点 4.MapReduce实例 5.MapReduce编程模型 6.MapReduce 内部逻辑 7.MapRed ...
- iOS Safari 中点击事件失效的解决办法
问题描述 当使用委托给一个元素添加click事件时,如果事件是委托到 document 或 body 上,并且委托的元素是默认不可点击的(如 div, span 等),此时 click 事件会失效. ...
- [转帖]音响及DarBee
红外与蓝牙的差别 1.距离 红外:对准.直接.1—2米,单对单 红外线可以用你的手机摄像头看到 蓝牙:10米左右,可加强信号,可以绕弯,可以不对准,可以不在同一间房间,链接最大数目可达7个,同时区分 ...
- UTF-8和GBK有什么区别?
字符均使用双字节来表示,只不过为区分中文,将其最高位都定成1. 至于UTF-8编码则是用以解决国际上字符的一种多字节编码,它对英文使用8位(即一个字节),中文使用24位(三个字节)来编码.对于英文字符 ...