Python 在Google Colab中打开JPG文件

Python 在Google Colab中打开JPG文件,python,Python,我有这个代码在谷歌colab上打开一个PNG文件 import numpy as np import matplotlib from PIL import Image %matplotlib inline import matplotlib.pyplot as plt import matplotlib.image as mpimg img = mpimg.imread('https://www.seekpng.com/png/full/161-1615982_doc-back-to-the-

我有这个代码在谷歌colab上打开一个PNG文件

import numpy as np
import matplotlib
from PIL import Image
%matplotlib inline
import matplotlib.pyplot as plt
import matplotlib.image as mpimg

img = mpimg.imread('https://www.seekpng.com/png/full/161-1615982_doc-back-to-the- 
future-png-doc-back.png')

imgplot = plt.imshow(img)
问题是这段代码只适用于PNG文件。我无法在Google Colab中打开JPG文件和GIF文件。我想从网上打开一张带有图片地址的图片,就像前面代码中的图片一样。 我知道你可以用这个代码打开JPG文件

from PIL import Image                                                                                
img = Image.open("https://upload.wikimedia.org/wikipedia/commons/c/c2/Girl_in_front_of_a_green_background.jpg")
img.show() 
但在编译时,它给了我以下错误FileNotFoundError:[Errno 2]没有这样的文件或目录:

请检查此文件

摘要:

您需要检索jpg或任何类型的文件保存,然后从Image.open()函数的路径中读取它

使用您可以获得的请求

可能也有用