tenn
tenn

Reputation: 37

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?

Upvotes: 1

Views: 18296

Answers (2)

Celius Stingher
Celius Stingher

Reputation: 18367

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()

Upvotes: 4

E. Gertz
E. Gertz

Reputation: 241

The solution is not to name the file the same as any of the modules being imported in that file.

read more in the example here:

https://geektechstuff.com/2020/06/13/attributeerror-partially-initialized-module-has-no-attribute-python/

Upvotes: 1

Related Questions