[英]open a .jpg image in python using matplotlib.image in python 3.6
我試圖在Python中使用matplotlib打開JPG圖像。 編輯'Spyder',Python3.6,WIndows 7
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import numpy as np
# Read in the image and print some stats
image = mpimg.imread(r'C:\Users\xxx\Python Code\mountain.jpg')
print('This image is: ',type(image),
'with dimensions:', image.shape)
但我收到以下錯誤...它說除了'.png'之外沒有其他圖像格式支持。
錯誤: - image = mpimg.imread(r'C:\\ Users \\ xxx \\ Python Code \\ mountain.jpg')
File "C:\temp\Continuum\anaconda3\lib\site-packages\matplotlib\image.py",
line 1284, in imread
'more images' % list(handlers))
ValueError: Only know how to handle extensions: ['png']; with Pillow
installed matplotlib can handle more images.
我經歷了各種文件。 其中說,為了打開'.jpg'圖像,必須安裝'Pillow'。 如果原生matplotlib調用無法打開圖像,那么它會自動回落到“枕頭”上。 (如果我錯了,請糾正我)
所以我安裝了“枕頭”。 但我仍然得到錯誤。
你能告訴我我想念的是什么嗎? (奇怪的是這個代碼在另一台計算機上運行。我無法驗證該機器中安裝的庫)
Matplotlib要求PIL( Python Imaging Library )使用.jpg
格式。 要使用它,您需要安裝Pillow ( 它是PIL的分支 )。
使用PIP安裝
pip install pillow
or
pip3 install pillow
使用Conda進行安裝
conda install pillow
你必須安裝PIL。 確保您使用的是anaconda python發行版。 轉到此鏈接或編寫此命令以直接安裝PIL
conda install -c anaconda pillow
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.