在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 列表(List) 的三种遍历方法实例 详解
Apr 15 Python
python3.5基于TCP实现文件传输
Mar 20 Python
python七夕浪漫表白源码
Apr 05 Python
Python中的self用法详解
Aug 06 Python
用Python批量把文件复制到另一个文件夹的实现方法
Aug 16 Python
Python 读取用户指令和格式化打印实现解析
Sep 02 Python
python实现在多维数组中挑选符合条件的全部元素
Nov 26 Python
pycharm激活码免费分享适用最新pycharm2020.2.3永久激活
Nov 25 Python
Python爬虫爬取有道实现翻译功能
Nov 27 Python
pycharm 关闭search everywhere的解决操作
Jan 15 Python
python实现高效的遗传算法
Apr 07 Python
使用python将HTML转换为PDF pdfkit包(wkhtmltopdf) 的使用方法
Apr 21 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
一个很方便的 XML 类!!原创的噢
2006/10/09 PHP
php+xml实现在线英文词典查询的方法
2015/01/23 PHP
通过MSXML2自动获取QQ个人头像及在线情况(给初学者)
2007/01/22 Javascript
jQuery 入门级学习笔记及源码
2010/01/22 Javascript
原生的html元素选择器类似jquery选择器
2014/10/15 Javascript
JavaScript返回上一页的三种方法及区别介绍
2015/07/04 Javascript
JS实现的自定义显示加载等待图片插件(loading.gif)
2016/06/17 Javascript
单行 JS 实现移动端金钱格式的输入规则
2017/05/22 Javascript
深入理解Vue-cli搭建项目后的目录结构探秘
2017/07/13 Javascript
js 判断一个数字是不是2的n次方幂的实例
2017/11/26 Javascript
Angular使用动态加载组件方法实现Dialog的示例
2018/05/11 Javascript
jquery实现自定义树形表格的方法【自定义树形结构table】
2019/07/12 jQuery
js tab栏切换代码实例解析
2019/09/03 Javascript
nodejs语言实现验证码生成功能的示例代码
2019/10/13 NodeJs
element-ui 实现响应式导航栏的示例代码
2020/05/08 Javascript
vuex中store存储store.commit和store.dispatch的用法
2020/07/24 Javascript
javascript实现随机抽奖功能
2020/12/30 Javascript
[01:36]DOTA2完美大师赛趣味视频之与队友相处的十万个技巧
2017/11/19 DOTA
python之PyMongo使用总结
2017/05/26 Python
python程序变成软件的实操方法
2019/06/24 Python
对Django中的权限和分组管理实例讲解
2019/08/16 Python
详解BeautifulSoup获取特定标签下内容的方法
2020/12/07 Python
HTML5拖放API实现拖放排序的实例代码
2017/05/11 HTML / CSS
澳大利亚香水在线:Price Rite Mart
2017/12/28 全球购物
泰国第一的化妆品网站:Konvy
2018/02/25 全球购物
方法名是否可以与构造器的名字相同
2012/06/04 面试题
C/C++程序员常见面试题二
2015/11/19 面试题
工程师求职简历的自我评价分享
2013/10/10 职场文书
社区学雷锋活动策划方案
2014/01/30 职场文书
计算机应用专业自荐信
2014/07/05 职场文书
会计系毕业求职信
2014/08/07 职场文书
银行员工犯错检讨书
2014/09/16 职场文书
个人整改措施书面材料
2014/10/24 职场文书
2015年社区中秋节活动总结
2015/03/23 职场文书
毕业酒会致辞
2015/07/29 职场文书
初中英语教学反思范文
2016/02/15 职场文书