ubuntu12.04.4下安装python模块PIL

来源:互联网 发布:sql select as 编辑:程序博客网 时间:2024/05/22 10:05
1. 问题描述:运行python文件出现以下信息:
    from PIL import ImageTk, ImageImportError: 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安装参照:http://blog.csdn.net/cryhelyxx/article/details/22514871
JPEG、ZLIB、FREETYPE2、LITTLECMS安装参照:http://blog.csdn.net/cryhelyxx/article/details/22589707
安装完 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 -irunning build_ext--------------------------------------------------------------------PIL 1.1.7 SETUP SUMMARY--------------------------------------------------------------------version       1.1.7platform      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 requiredlibrary, and set the corresponding ROOT variable in thesetup.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 ./PILBinary 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 vfrom line #24 of selftest.testimageExpected: ('JPEG', 'RGB', (128, 128))Got: decoder jpeg not available1 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!!!
0 0
原创粉丝点击