安裝PIL
,問題多多,現將出現問題,原因,以及解決方法總結如下:
PIL的官方版本,但是最后一次維護是2009年,現以宣布停止維護,可以運行在python2.7上。
PillowPIL
的fork版本,還在繼續維護更新,建議安裝Pillow
。
在安裝Pillow之前,請卸載PIL
sudo pip uninstall PIL
安裝Pillow 依賴,下面安裝是真對ubuntu14.04版本
libfreetype6-dev liblcms2-dev libwebp-dev tcl8.6-dev tk8.6-dev python-tk```
下面介紹各包提供功能,以及需要的包版本限制(重要)
ibjpeg provides JPEG functionality.
- Pillow has been tested with libjpeg versions 6b, 8, 9, and 9a and libjpeg-turbo version 8.
- Starting with Pillow 3.0.0, libjpeg is required by default, but may be disabled with the--disable-jpeg
flag.
zlib provides access to compressed PNGs
- Starting with Pillow 3.0.0, zlib is required by default, but may be disabled with the--disable-zlib
flag.
libtiff provides compressed TIFF functionality
- Pillow has been tested with libtiff versions 3.x and 4.0
libfreetype provides type related services
littlecms provides color management
- Pillow version 2.2.1 and below uses liblcms1, Pillow 2.3.0 and above uses liblcms2. Tested with 1.19 and 2.7.
libwebp provides the WebP format.
- Pillow has been tested with version 0.1.3, which does not read transparent WebP files.
- Versions 0.3.0 and above support transparency.
tcl/tk provides support for tkinter bitmap and photo images.
openjpeg provides JPEG 2000 functionality.
- Pillow has been tested with openjpeg 2.0.0 and 2.1.0.
- Pillow does not support the earlier 1.5 series which ships with Ubuntu and Debian.
在我的ubuntu14.04
中openjpeg
版本過低,所以找到openjpeg的官方網站編譯安裝最新版的openjpeg
- 下載 openjpeg 包
-
cd DownloadPath
tar -xzvf Download file name
cd Download file
sudo cmake .
sudo make
sudo make install
完成依賴安裝后,使用命令sudo pip install Pillow
安裝Pillow
圖片中的內容包括Pillow中的各個功能是否支持,如果這些功能出現unsupport ,那么就參考上面包提供功能,檢測系統下依賴包是否滿足Pillow的要求。
最后打開python解釋器,輸入
from PIL import Image
如果成功導入,說明 安裝成功。
在我的ubuntu 14.04安裝成功后,在導入仍然提示:[PIL - libopenjp2.so: cannot open shared object file: No such file or directory]
這樣的錯誤,在stackoverflow找到了解決方法:
-
wheries libopenjp2
找到動態鏈接庫的文件位置 -
cd \etc ls -l |grep 'ld.so.conf'
找到ld.so.conf
文件 - 編輯該文件,將
libopenjp2
庫的路徑,添加到ld.so.conf
文件中 -
sudo ldconfig
下面是python找不到動態鏈接庫的原因:以及設置 LD_LIBRARY_PATH有時不能良好解決問題的原因:
sys.path is only searched for Python modules. For dynamic linked libraries, the paths searched must be in LD_LIBRARY_PATH. Check if your LD_LIBRARY_PATH includes /usr/local/lib, and if it doesn't, add it and try again.In Linux, the environment variable LD_LIBRARY_PATH is a colon-separated set of directories where libraries should be searched for first, before the standard set of directories; this is useful when debugging a new library or using a nonstandard library for special purposes. The environment variable LD_PRELOAD lists shared libraries with functions that override the standard set, just as /etc/ld.so.preload does. These are implemented by the loader /lib/ld-linux.so. I should note that, while LD_LIBRARY_PATH works on many Unix-like systems, it doesn't work on all; for example, this functionality is available on HP-UX but as the environment variable SHLIB_PATH, and on AIX this functionality is through the variable LIBPATH (with the same syntax, a colon-separated list).