如何使用python打开png和jpg文件?

如何使用python打开png和jpg文件?,python,image,png,jpeg,Python,Image,Png,Jpeg,我需要一个程序来打开png文件。我在网上找到了这个,但这给了我一个错误 from PIL import Image im = Image.open("D:/foto's/fbshare.png") im.show() 这就是错误: AttributeError: partially initialized module 'PIL.Image' has no attribute 'open' (most likely due to a circular import)

我需要一个程序来打开png文件。我在网上找到了这个,但这给了我一个错误

from PIL import Image

im = Image.open("D:/foto's/fbshare.png")

im.show()
这就是错误:

AttributeError: partially initialized module 'PIL.Image' has no attribute 'open' (most likely due to a circular import)

有人有这个问题的解决方案吗?

解决方案是将文件命名为与该文件中导入的任何模块不同的名称

请阅读以下示例中的更多内容:


我使用
matplotlib.image
作为
mpimg
matplotlib.pyplot
作为
plt

import matplotlib.pyplot as plt
import matplotlib.image as mpimg
image_path = "D:/foto's/fbshare.png"
image = mpimg.imread(image_path)
plt.imshow(image)
plt.show()

你有没有其他同名的文件?试着导入PIL.Image或者试着直接导入Image;如果需要,pip首先安装映像,它会向我提供以下错误模块NotFoundError:没有名为“matplotlib.mpimg”的模块完成!是的,我把mpimg和真名
matplotlib.image
混合在一起。它有效吗?请让我知道!对不起,是的,它确实很好用