Reputation: 37
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
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
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:
Upvotes: 1