Windows安装Python图像处理库:PIL模块

Posted on 2015-01-12 in Python by yucongchen

平常一般都在Linux下用Python,今天女票突然说让帮忙把一些图片全部弄成一个分辨率的,作为程序员,这种重复的工作还是交给计算机吧。 到PIL官网下载一个,python imaging library 1.1.7 for Python 2.7 (windows only)。

exe文件,直接双击,提示:Python version 2.7 required, which was not found in the registry

Python version 2.7 required, which was not found in the registry

不是装了Python吗,检查了下环境变量,没有问题。 然后上网百度,发现我的系统是win7 64位的,而PIL官网提供的下载包都是32位的,可以在这里看到 http://effbot.org/downloads#pil

  • 64位检查注册表的位置是: HKLM|HKCU\SOFTWARE\
  • 32位检查注册表的位置是: HKLM|HKCU\SOFTWARE\wow6432node\

然后,有人提供了非官方的64位库: http://www.lfd.uci.edu/~gohlke/pythonlibs/

叫做Pillow,下载下来,是个 .whl 结尾的文件,这个其实就是python使用的一种压缩文件,后缀名改成zip,可以打开。 这个需要用 pip 安装。 如果没有在windows上安装pip,可以参考我的另一篇文章:安装pip

pip install Pillow-2.7.0-cp27-none-win_amd64.whl 即可。 注意,这里有一段 Pillow is a replacement for PIL, the Python Image Library, which provides image processing functionality and supports many file formats.

Use 'from PIL import Image' instead of 'import Image'.

意思就是说,要用 from PIL import Image 代替 import Image 然后进python 命令行 from PIL import Image OK,安装成功了。用法和PIL一样。

另外,还有通过源码自己编译的方法在windows上安装,可以参考: http://www.crifan.com/python_install_pip_error_python_version_2_7_required_which_was_not_found_in_the_registry/