PIL、Pillow安裝使用方法

PIL(Python Imaging Library)是Python經常使用的圖像處理庫,而Pillow是PIL的一個友好Fork,提供了了普遍的文件格式支持,強大的圖像處理能力,主要包括圖像儲存、圖像顯示、格式轉換以及基本的圖像處理操做等。python

Pillow的文檔:http://pillow.readthedocs.io/en/latest/linux

Pillow的github:https://github.com/python-pillow/Pillowgit

-----------------------------------------------------------------github

0x0. Pillow的注意事項ubuntu

複製代碼
Pillow and PIL cannot co-exist in the same environment. Before installing Pillow, please uninstall PIL.
Pillow >= 1.0 no longer supports 「import Image」. Please use 「from PIL import Image」 instead.
Pillow >= 2.1.0 no longer supports 「import _imaging」. Please use 「from PIL.Image import core as _imaging」 instead.

Pillow < 2.0.0 supports Python versions 2.4, 2.5, 2.6, 2.7.
Pillow >= 2.0.0 < 4.0.0 supports Python versions 2.6, 2.7, 3.2, 3.3, 3.4, 3.5
Pillow >= 4.0.0 supports Python versions 2.7, 3.3, 3.4, 3.5, 3.6
複製代碼

 

0x1. windows安裝PILwindows

PIL安裝很麻煩,推薦下載exe直接安裝app

PIL官網:http://pythonware.com/products/pil/python2.7

但如今裏面下載連接訪問不了,我把32位和64位版本上傳到博客園以供下載。ide

PILwin32:http://files.cnblogs.com/files/pcat/PILwin32.zipspa

PILwin64:http://files.cnblogs.com/files/pcat/PILwin64.zip

 

0x2. windows安裝Pillow

pip install Pillow

或者在http://www.lfd.uci.edu/~gohlke/pythonlibs/#pillow 下載wheel文件使用pip安裝

 

0x3. linux安裝python2.七、pip

sudo apt-get install python
sudo apt-get install python-pip

 

0x4. linux安裝Pillow

在linux裏安裝PIL不怎麼建議,依賴也多,並且會有各類報錯。

kali的python默認已安裝了Pillow。

在debian/ubuntu裏安裝Pillow:

sudo apt-get install python-imaging

或者

sudo pip install -I --no-cache-dir -v Pillow

python-imaging安裝後的支持import Image

 

0x5. Pillow wrapper for PIL compatibility

github地址:https://github.com/yinpeng/pillow-pil

其做者是這樣介紹:他項目中也使用Pillow替代了PIL,不過PIL和Pillow的import語句不兼容致使本項目代碼修改倒還好說,問題是後來使用的依賴PIL的第三方組件不兼容,咱們既不想同時安裝Pillow和PIL,又不想修改第三方組件的源代碼,因此他寫了個很簡單的Pillow-PIL,使得依賴PIL的第三方組件不用修改源代碼就能夠使用Pillow了。安裝法子以下:

pip install Pillow-PIL

 

0x6. PIL一些報錯

ImportError:The _imagingft C module is not installed

這個是在windows裏安裝PIL所報錯,建議直接exe安裝。

PIL.Image.open() IOError: cannot identify image file

首先檢查圖片是否是正確的,若是各類檢查過仍是有問題建議重裝PIL

 

0x7. Pillow報KeyError問題

複製代碼
python
>>> import Image
>>> Image.init()
1
>>> Image.SAVE.keys()
['PCX', 'HDF5', 'EPS', 'MSP', 'XBM', 'WEBP', 'BUFR', 'PPM', 'BMP', 'TGA', 'ICO', 'TIFF', 'JPEG', 'SPIDER', 'GIF', 'GRIB', 'IM', 'FITS', 'PDF', 'WMF', 'MPO', 'PALM', 'JPEG2000', 'PNG']
相關文章
相關標籤/搜索