安裝python庫Pillow(PIL)出現問題及解決方法

安裝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.

  1. Pillow has been tested with libjpeg versions 6b, 8, 9, and 9a and libjpeg-turbo version 8.
  2. 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

  1. 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

  1. Pillow has been tested with libtiff versions 3.x and 4.0

libfreetype provides type related services

littlecms provides color management

  1. 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.

  1. Pillow has been tested with version 0.1.3, which does not read transparent WebP files.
  2. Versions 0.3.0 and above support transparency.

tcl/tk provides support for tkinter bitmap and photo images.

openjpeg provides JPEG 2000 functionality.

  1. Pillow has been tested with openjpeg 2.0.0 and 2.1.0.
  2. Pillow does not support the earlier 1.5 series which ships with Ubuntu and Debian.

在我的ubuntu14.04openjpeg版本過低,所以找到openjpeg的官方網站編譯安裝最新版的openjpeg

  1. 下載 openjpeg
  2. cd DownloadPath tar -xzvf Download file name
  3. cd Download file
  4. sudo cmake .
  5. sudo make
  6. sudo make install

完成依賴安裝后,使用命令sudo pip install Pillow安裝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找到了解決方法:

  1. wheries libopenjp2 找到動態鏈接庫的文件位置
  2. cd \etc ls -l |grep 'ld.so.conf' 找到ld.so.conf文件
  3. 編輯該文件,將libopenjp2庫的路徑,添加到ld.so.conf文件中
  4. 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).

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容