在Mac OS系统上安装Python的Pillow库的教程


Posted in Python onNovember 20, 2015

今天帮朋友做个python的小工具,发现系统上缺少ptyhon的支持库,返回如下信息

ImportError: No module named PIL 
然后就下载安装,因为机器上也没有python的管理工具pip,所以也一并安装
1. 安装pip

sudo easy_install pip

pip 安装成功就可以直接安装pil或者pillow

2. 通过命令pip install pil

pip install Pil
Downloading/unpacking Pil 
 Could not find any downloads that satisfy the requirement Pil 
 Some externally hosted files were ignored (use --allow-external Pil to allow). 
Cleaning up... 
No distributions at all found for Pil 
Storing debug log for failure in /Users/macbook/Library/Logs/pip.log

3. 所以就安装pillow

pip install --use-wheel Pillow
Downloading/unpacking Pillow 
 Downloading Pillow-2.4.0.zip (6.5MB): 5.0MB downloaded 
Cleaning up...

弄了会别的回来发现还没有下载完,这叫一个慢呀,于是放弃
4. Git

通过git下载源码地址https://github.com/python-imaging/Pillow

git clone https://github.com/python-imaging/Pillow.git

然后开始编译安装

4.1

python setup.py build_ext -i

编译完之后会提示运行测试例子,并且发现JPEG support not available

-------------------------------------------------------------------- 
version   Pillow 2.4.0 
platform   darwin 2.7.5 (default, Aug 25 2013, 00:04:04) 
       [GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] 
-------------------------------------------------------------------- 
--- TKINTER support available 
*** JPEG support not available 
*** OPENJPEG (JPEG2000) support not available 
--- ZLIB (PNG/ZIP) support available 
*** LIBTIFF support not available 
--- FREETYPE2 support available 
*** LITTLECMS2 support not available 
*** WEBP support not available 
*** WEBPMUX 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.

4.2 因为JPEG support not available,运行python selftest.py报告错误

1 tests of 57 failed. 

于是只好卸载pillow

可以通过pip命令来卸载

pip uninstall pillow 
sudo pip uninstall pillow
Password: 
Uninstalling Pillow: 
 /Library/Python/2.7/site-packages/Pillow-2.4.0-py2.7-macosx-10.9-intel.egg 
 /usr/local/bin/pilconvert.py 
 /usr/local/bin/pildriver.py 
 /usr/local/bin/pilfile.py 
 /usr/local/bin/pilfont.py 
 /usr/local/bin/pilprint.py 
Proceed (y/n)? y  
  Successfully uninstalled Pillow 

成功之后需要安装libjpeg的支持

brew install libjpeg

安装成功之后重新编译pillow

-------------------------------------------------------------------- 
version   Pillow 2.4.0 
platform   darwin 2.7.5 (default, Aug 25 2013, 00:04:04) 
       [GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] 
-------------------------------------------------------------------- 
--- TKINTER support available 
--- JPEG support available 
*** OPENJPEG (JPEG2000) support not available 
--- ZLIB (PNG/ZIP) support available 
*** LIBTIFF support not available 
--- FREETYPE2 support available 
*** LITTLECMS2 support not available 
*** WEBP support not available 
*** WEBPMUX support not available 
-------------------------------------------------------------------- 
python selftest.py  

-------------------------------------------------------------------- 
Pillow 2.4.0 TEST SUMMARY  
-------------------------------------------------------------------- 
Python modules loaded from /Users/macbook/yyang/app-devel-source/python/Pillow/PIL 
Binary modules loaded from /Users/macbook/yyang/app-devel-source/python/Pillow/PIL 
-------------------------------------------------------------------- 
--- PIL CORE support ok 
--- TKINTER support ok 
--- JPEG support ok 
*** JPEG 2000 support not installed 
--- ZLIB (PNG/ZIP) support ok 
*** LIBTIFF support not installed 
--- FREETYPE2 support ok 
*** LITTLECMS2 support not installed 
*** WEBP support not installed 
-------------------------------------------------------------------- 
Running selftest: 
--- 57 tests passed.

最后执行安装

sudo python setup.py install
Python 相关文章推荐
Python实现约瑟夫环问题的方法
May 03 Python
Python的几个高级语法概念浅析(lambda表达式闭包装饰器)
May 28 Python
Python的Flask框架及Nginx实现静态文件访问限制功能
Jun 27 Python
Python cookbook(数据结构与算法)找到最大或最小的N个元素实现方法示例
Feb 13 Python
Django中STATIC_ROOT和STATIC_URL及STATICFILES_DIRS浅析
May 08 Python
python逆序打印各位数字的方法
Jun 25 Python
python文字和unicode/ascll相互转换函数及简单加密解密实现代码
Aug 12 Python
python框架flask入门之环境搭建及开启调试
Jun 07 Python
通过实例解析python创建进程常用方法
Jun 19 Python
记录一下scrapy中settings的一些配置小结
Sep 28 Python
python自动化操作之动态验证码、滑动验证码的降噪和识别
Aug 30 Python
python入门学习关于for else的特殊特性讲解
Nov 20 Python
详解Python编程中time模块的使用
Nov 20 #Python
Windows上配置Emacs来开发Python及用Python扩展Emacs
Nov 20 #Python
将Emacs打造成强大的Python代码编辑工具
Nov 20 #Python
Python聚类算法之DBSACN实例分析
Nov 20 #Python
Python聚类算法之凝聚层次聚类实例分析
Nov 20 #Python
Python聚类算法之基本K均值实例详解
Nov 20 #Python
Python实现将xml导入至excel
Nov 20 #Python
You might like
php获取域名的google收录示例
2014/03/24 PHP
php通过PHPExcel导入Excel表格到MySQL数据库的简单实例
2016/10/29 PHP
jquery获取tr并更改tr内容示例代码
2014/02/13 Javascript
jquery取消选择select下拉框示例代码
2014/02/22 Javascript
JavaScript中使用ActiveXObject操作本地文件夹的方法
2014/03/28 Javascript
js实现的类似于asp数据字典的数据类型代码实例
2014/09/03 Javascript
Windows系统下使用Sublime搭建nodejs环境
2015/04/13 NodeJs
整理Javascript基础语法学习笔记
2015/11/29 Javascript
Google 地图API资料整理及详细介绍
2016/08/06 Javascript
纯css下拉菜单 无需js
2016/08/15 Javascript
微信小程序 input输入及动态设置按钮的实现
2017/10/27 Javascript
基于Vue2x的图片预览插件的示例代码
2018/05/14 Javascript
详解extract-text-webpack-plugin 的使用及安装
2018/06/12 Javascript
vue通信方式EventBus的实现代码详解
2019/06/10 Javascript
Vue-resource安装过程及使用方法解析
2020/07/21 Javascript
关于Js中new操作符的作用详解
2021/02/21 Javascript
详解Python中的__new__、__init__、__call__三个特殊方法
2016/06/02 Python
python2 与python3的print区别小结
2018/01/16 Python
Python日期时间对象转换为字符串的实例
2018/06/22 Python
python 美化输出信息的实例
2018/10/15 Python
Python socket实现多对多全双工通信的方法
2019/02/13 Python
python之yield和Generator深入解析
2019/09/18 Python
Python解压 rar、zip、tar文件的方法
2019/11/19 Python
CSS3 制作绽放的莲花采用效果叠加实现
2013/01/31 HTML / CSS
理工科学生的自我评价
2013/12/15 职场文书
关于幼儿的自我评价
2013/12/18 职场文书
美术专业个人自我评价
2014/01/18 职场文书
2014年三万活动总结
2014/04/26 职场文书
读书之星事迹材料
2014/05/12 职场文书
中学生运动会口号
2014/06/07 职场文书
我的梦想演讲稿500字
2014/08/21 职场文书
关于读书的演讲稿800字
2014/08/27 职场文书
小学安全教育主题班会
2015/08/12 职场文书
2016年秋季运动会通讯稿
2015/11/25 职场文书
聊聊redis-dump工具安装问题
2022/01/18 Redis
Nginx+Windows搭建域名访问环境的操作方法
2022/03/17 Servers