您的位置:首页 > 编程语言 > Python开发

ubuntu12.04.4下安装python模块PIL

2014-03-30 15:00 495 查看
1. 问题描述:运行python文件出现以下信息:

from PIL import ImageTk, Image
ImportError: No module named PIL

2. 解决方法:

(1) 安装python-imaging-tk

sudo apt-get install python-imaging-tk

(2) 安装Python Imaging Library(PIL):

PIL下载地址:http://www.pythonware.com/products/pil/

我目前下载的是Python Imaging Library 1.1.7 Source Kit, 包包名为 Imaging-1.1.7.tar.gz

解压:

tar -xzvf Imaging-1.1.7.tar.gz

切换到管理员命令行(ps:这里说明下, 为什么要切换到管理员身份呢? 因为安装的时候要创建文件夹, 而普通用户身份是无法做到的, 如果不信你试下普通用户身份安装就知道了):

sudo -s

以管理员身份安装:

python setup.py build


由上面可知JPEG、ZLIB、FREETYPE2、LITTLECMS还没安装, TKINTER库已安装.

Tkinter安装参照:/article/8659013.html

JPEG、ZLIB、FREETYPE2、LITTLECMS安装参照:/article/8659015.html

安装完 TKINTER、 JPEG、 ZLIB、FREETYPE2、LITTLECMS后, 再次检测:

python setup.py build




检测模块是否可用:

python setup.py build_ext -i

信息如下:

cryhelyxx@ada:~/下载/Imaging-1.1.7$ python setup.py build_ext -i
running build_ext
--------------------------------------------------------------------
PIL 1.1.7 SETUP SUMMARY
--------------------------------------------------------------------
version       1.1.7
platform      linux2 2.7.6 (default, Mar 30 2014, 00:48:22)
[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.

测试模块:

python selftest.py

信息如下:

cryhelyxx@ada:~/下载/Imaging-1.1.7$ python selftest.py
--------------------------------------------------------------------
PIL 1.1.7 TEST SUMMARY
--------------------------------------------------------------------
Python modules loaded from ./PIL
Binary modules loaded from ./PIL
--------------------------------------------------------------------
--- PIL CORE support ok
--- TKINTER support ok
*** JPEG support not installed
*** ZLIB (PNG/ZIP) support not installed
--- FREETYPE2 support ok
*** LITTLECMS support not installed
--------------------------------------------------------------------
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.
cryhelyxx@ada:~/下载/Imaging-1.1.7$

显而易见, TKINTER、JPEG、 ZLIB、FREETYPE2都可用, LITTLECMS不可用, 但JPEG、ZLIB、LITTLECMS还是未成功安装, 有待研究...。

继续安装PIL:

python setup.py install

3. 检验是否成功安装python模块PIL:

终端输入:

python

from PIL import ImageTk, Image

如下:


4. OK, 没消息就是好消息, 恭喜你已成功安装python模块PIL...Enjoy it!!!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: