Python Imaging Library (PIL) 为你的 Python 解释器增添了图像处理能力。但其安装步骤颇为复杂,下面是从源码安装的步骤。
wget http://effbot.org/media/downloads/Imaging-1.1.7.tar.gz
tar -xvf Imaging-1.1.7.tar.gz
cd Imaging-1.1.7/
python setup.py build_ext -i
出现提示:
--------------------------------------------------------------------
PIL 1.1.7 SETUP SUMMARY
--------------------------------------------------------------------
version 1.1.7
platform linux2 2.7.12 (default, Nov 19 2016, 06:48:10)
[GCC 5.4.0 20160609]
--------------------------------------------------------------------
*** TKINTER support not available
*** JPEG support not available
*** ZLIB (PNG/ZIP) support not available
*** FREETYPE2 support not available
*** LITTLECMS 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.
running build_scripts
发现依赖未安装,接下来安装依赖。
安装 TKINTER
sudo apt-get install python-tk
python setup.py build
出现提示:
--------------------------------------------------------------------
PIL 1.1.7 SETUP SUMMARY
--------------------------------------------------------------------
version 1.1.7
platform linux2 2.7.12 (default, Nov 19 2016, 06:48:10)
[GCC 5.4.0 20160609]
--------------------------------------------------------------------
*** TKINTER support not available (Tcl/Tk 8.6 libraries needed)
*** JPEG support not available
*** ZLIB (PNG/ZIP) support not available
*** FREETYPE2 support not available
*** LITTLECMS 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.
running build_scripts
根据提示安装 Tcl/Tk :
wget http://prdownloads.sourceforge.net/tcl/tcl8.6.6-src.tar.gz
wget http://prdownloads.sourceforge.net/tcl/tk8.6.6-src.tar.gz
tar -xvf tcl8.6.6-src.tar.gz
cd tcl8.6.6/unix/
./configure && make && sudo make install
cd .. && cd tk8.6.6/unix/
./configure && make && sudo make install
安装完成后,运行 python setup.py build_ext -i
会出现提示:
--------------------------------------------------------------------
PIL 1.1.7 SETUP SUMMARY
--------------------------------------------------------------------
version 1.1.7
platform linux2 2.7.12 (default, Nov 19 2016, 06:48:10)
[GCC 5.4.0 20160609]
--------------------------------------------------------------------
--- TKINTER support available
*** JPEG support not available
*** ZLIB (PNG/ZIP) support not available
*** FREETYPE2 support not available
*** LITTLECMS 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.
running build_scripts
此时,TKINTER 依赖安装好了。接下来安装 JPEG 的依赖。
wget http://www.ijg.org/files/jpegsrc.v9b.tar.gz
tar -xvf jpegsrc.v9b.tar.gz
cd jpeg-9b/
./configure && make && sudo make install
安装完成后,运行 python setup.py build_ext -i
会出现提示:
--------------------------------------------------------------------
PIL 1.1.7 SETUP SUMMARY
--------------------------------------------------------------------
version 1.1.7
platform linux2 2.7.12 (default, Nov 19 2016, 06:48:10)
[GCC 5.4.0 20160609]
--------------------------------------------------------------------
--- TKINTER support available
--- JPEG support available
*** ZLIB (PNG/ZIP) support not available
*** FREETYPE2 support not available
*** LITTLECMS 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.
running build_scripts
此时,JPEG 依赖安装完成, 接下来安装 ZLIB 依赖。
wget http://prdownloads.sourceforge.net/libpng/zlib-1.2.11.tar.gz
tar -xvf zlib-1.2.11.tar.gz
cd zlib-1.2.11/
./configure && make && make install
此时,ZLIB 依赖安装完成,接下来安装 FREETYPE。
wget https://sourceforge.net/projects/freetype/files/freetype2/2.7.1/freetype-2.7.1.tar.bz2
tar -jxvf freetype-2.7.1.tar.bz2
cd freetype-2.7.1/
./configure && make && sudo make install
此时 FREETYPE 依赖安装完成,接下来安装 LITTLECMS。
wget https://sourceforge.net/projects/lcms/files/lcms/1.19/lcms-1.19.tar.gz
tar -xvf lcms-1.19.tar.gz
cd lcms-1.19/
./configure && make && sudo make install
此时,运行 python setup.py build_ext -i
会出现:
PIL 1.1.7 SETUP SUMMARY
--------------------------------------------------------------------
version 1.1.7
platform linux2 2.7.12 (default, Nov 19 2016, 06:48:10)
[GCC 5.4.0 20160609]
--------------------------------------------------------------------
--- TKINTER support available
--- JPEG support available
--- ZLIB (PNG/ZIP) support available
--- FREETYPE2 support available
--- LITTLECMS support available
--------------------------------------------------------------------
To check the build, run the selftest.py script.
running build_scripts
至此,所有依赖安装完毕。接下来 cd 到 Imaging-1.1.7 目录。
测试
python selftest.py
会出现:
--------------------------------------------------------------------
PIL 1.1.7 TEST SUMMARY
--------------------------------------------------------------------
Python modules loaded from ./PIL
Binary modules loaded from ./PIL
--------------------------------------------------------------------
--- PIL CORE support ok
--- TKINTER support ok
--- JPEG support ok
--- ZLIB (PNG/ZIP) support ok
--- FREETYPE2 support ok
*** LITTLECMS support not installed
--------------------------------------------------------------------
Running selftest:
--- 57 tests passed.
安装:
sudo python setup.py install
运行:
$ python
Python 2.7.12 (default, Nov 19 2016, 06:48:10)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import Image
>>>
至此,PIL 安装成功。
PS:
可以使用 pillow 作为 PIL 的替代,pillow 是 PIL 的一个“友好”分支。使用 pip install pillow
安装。