第一次想用python写个小程序,需要用到PIL,折腾了一晚上才安装好PIL.
期间在网上找过各种教程,综合后搞定:
- Install Xcode from the App Store.
- Open Xcode and open Xcode Preferences.
- Click on the Downloads tab, and you’ll see Command Line Tools. Click the Install button to install the Command Line Tools. (This provides gcc to compile PIL)
- 这时我的环境使用sudo pip install PIL出现如下错误:
6072969a2565e1_
-
通过 sudo easy_install --upgrade pip 解决
- 这时pip 命令已经可以使用,但出现如下总是:
unable to execute gcc-4.2: No such file or directory
-
这时 通过
sudo ln -s /usr/bin/gcc /usr/bin/gcc-4.2 解决
- 最后sudo pip install PIL 成功
———————————————————————————————-
此时在处理图片时,还会报以下的错误:
decoder jpeg not available。。。。
这是还没有安装jpeg, 但只是简单安装jpeg(brew install jpeg)后,还是会有同类问题。
这和PIL的安装有关系了。这时我们应该通过下载source,并且通过修改其中的setup.py文件中JPEG_ROOT = None => JPEG_ROOT = libinclude(“/usr/local”) 这一项来fix这问题。
做完这一步后,可以通过 >>> import Image来验证,如果没再提示错误信息,表明ok了。
ref: http://www.pythonware.com/products/pil/