(linux / win)怎樣安裝Pillow和PIL-Pillow相容包?

來源:互聯網
上載者:User

標籤:error:   latest   直接   versions   技術分享   orm   tle   line   error   

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.5Pillow >= 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 pythonsudo 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‘]

如果Image.SAVE.keys()輸出為空白,則說明沒有找到save format key,在產生圖片時就會報KeyError, 此時就需要把import Image改成from PIL import Image

(linux / win)怎樣安裝Pillow和PIL-Pillow相容包?

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.