ModuleNotFoundError: No module named 'PIL' so I'm not sure what to try next for my ImageViewer

Question:

I can’t figure out why my code couldn’t work.

from tkinter import *
"""
We need the Pillow library (or PIL) to import images in out application)
I need to import both ImageTk and Image
"""
from PIL import ImageTk, Image

"""
doens't work at the moment bc I can't figure out what's wrong with PIL
"""

root = Tk()
root.title("Icono, Boton Exit y Imagenes")
root.geometry("200x100")

'''
root.iconbitmap("c:/gui/codemy.ico")

this is to put a personalized icon to the window application
'''

my_img = imageTk.PhotoImage(Image.open("something.png"))
my_label = Label(image=my_img)
my_label.pack()


button_quit = Button(root, text="Salir del programa", command=root.destroy) 
button_quit.pack()

"""
https://www.geeksforgeeks.org/how-to-close-a-tkinter-window-with-a-button/

for other examples of exit button

also command=root.quit

"""

root.mainloop()

I tried to look it up around and from what I’ve been asked by others, I don’t have two Python versions installed;

I installed Pillow;

And PIL I couldn’t install since pip could not find it.

I’m not sure what to try next.

Thank you for reading my question.

EDIT:
This is the traceback.

Traceback (most recent call last):

File "F:python ejerciciosTkIconsImagesExitButtons.py", line 6, >in

from PIL import ImageTk, Image

ModuleNotFoundError: No module named ‘PIL’

Edit2:
These are the warnings which I Kind of find confusing?

Line 6 : Name "Image" already defined (possibly by an import)

Line 6 : Unused ImageTk imported from PIL
It looks like the imported module or variable is not used.

Line 22 : Name "imageTk" is not defined

Line 22 : "Type[Image]" has no attribute "open"

Final edit: Found the problem. Thanks to those who tried to help me out.

Asked By: AlElM

||

Answers:

Hey there you can try the following-

  1. Make corrections in your code

    my_img = ImageTk.PhotoImage(Image.open("something.png"))

  2. Try to update your pip version by using the command in command prompt or powershell
    pip install --upgrade pip

Answered By: Aditya Tripathi

So my actual problem was that I had more than one Python.exe installed and that Thonny (the IDE I use) didn’t actually have the Pillow package so when I would run the app, it failed.
Thanks a lot for the help.

Answered By: AlElM