ImportError: cannot import name 'ImageTK'

32,057

Solution 1

You have a typo in the module you want to import. The k in ImageTk should be lower case:

from PIL import Image, ImageTk

this should solve your problem

and in your script you have another case typo, PhotoImage is CamelCase:

main_photo = ImageTk.PhotoImage(main_image)

Solution 2

Use this command for Python 3

 sudo apt-get install python3-pil.imagetk

Solution 3

ImageTK is k(small letter) not K (capital letter)

from PIL import Image, ImageTk

Solution 4

Install it using this command.

sudo apt-get install python-imaging-tk

Solution 5

To install for python2 type in terminal:
sudo apt-get install python-pil.imagetk

For python3 type:
sudo apt-get install python3-pil.imagetk

To import Image and ImageTk:
from PIL import Image, ImageTk

There's a typo in your script, it will be PhotoImage:
main_photo = ImageTk.PhotoImage(main_image)

Share:
32,057
Brenden
Author by

Brenden

Updated on September 22, 2021

Comments

  • Brenden
    Brenden over 2 years

    I cannot seem to figure out how to fix a problem with my code regarding import ImageTK from PIL. I have searched and downloaded Pillow different ways and the error of the code is still the same.

    Traceback (most recent call last):
    File "8_Age_Calculator_App.py", line 3, in <module>
      from PIL import Image, ImageTK
    ImportError: cannot import name 'ImageTK'
    

    These are the import codes of the file

    import PIL
    from PIL import Image, ImageTK
    import tkinter as tk
    import datetime
    

    and this is the code that is trying to import the image

    main_image = Image.open('/Users/Brenden/Documents/Python_OOP/old-people-
    running-illo_h.jpg')
    main_image.thumbnail((100,100), Image.ANTIALIAS)
    main_photo = ImageTK.Photoimage(main_image)
    main_label_image = tk.Label(image=main_photo)
    main_label.grid(column=1, row=0)
    

    How may I fix this problem?