我想在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 调用无法打开图像,则会自动回退到 'Pillow'。(如果我说错了,请纠正我)
所以我安装了 'Pillow',但仍然遇到错误。
你能告诉我我错过了什么吗?(奇怪的是这段代码在另一台计算机上运行正常,我无法验证该计算机上安装了哪个库)