Search code examples
pythonimagepngjpeg

how can i open png and jpg files with python?


i need a program to open png files. I found this on the internet, but this gives me an error.

from PIL import Image

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

im.show()

this is the error:

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

does anybody have the solution to this problem?


Solution

  • I use matplotlib.image as mpimg and matplotlib.pyplot as 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()