PIL、Pillow安裝使用方法


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

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

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

-----------------------------------------------------------------

0x0. Pillow的注意事項

復制代碼
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安裝PIL

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

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

但現在里面下載鏈接訪問不了,我把32位和64位版本上傳到博客園以供下載。

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

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.7、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']


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM