Ghulam Muhammad
Ghulam Muhammad

Reputation: 11

Attribute Error while using Image Module from PIL library in Python 3

I am building a simple python 3 program to open and resize an image. I am using Pycharm. I imported Image from PIL and tried to run the following command:

image1 = Image.open('<file location>')

but the interpreter is showing an Attribute Error that type Image has no attribute open.

My program is:

from PIL import Image
from tkinter import *

root = Tk()

image2 = Image.open('hp png.png')

hp_image2 = Label(root , image = image2)

hp_image2.pack(fill = BOTH)

root.mainloop()

and the output is: enter image description here

Upvotes: 1

Views: 382

Answers (2)

Hamza Lachi
Hamza Lachi

Reputation: 1064

Try This:

import PIL.Image
from tkinter import Tk

image2 = PIL.Image.open('hp png.png')

Hopefully it will work

Upvotes: 1

CDJB
CDJB

Reputation: 14506

The import from tkinter is replacing the import from PIL. Consider replacing

from tkinter import *

with

import tkinter as tk

and update the rest of your code with the new import.

Upvotes: 2

Related Questions