0

As I try to import PIL as shown below, it shows me an error message (also shown below).

Code:

from tkinter import *

#import tkinter as tk

from PIL import ImageTk, Image

root = Tk()

root.title('Title here')

root.iconbitmap('images/logo.ico')

root.mainloop() 

Error Message:

Traceback (most recent call last):
  File "d:/College/Sem4/Human Computer Interaction/Full project/code here/Home.py", line 2, in <module>
    from PIL import ImageTk, Image
ModuleNotFoundError: No module named 'PIL'

Note:

  • I have Pillow 8.2.0 installed on my system.
  • I tried doing that "pip install image" and "import Image" thing too but it also didn't work either.
ack
  • 1,451
  • 1
  • 14
  • 18
Shrez Ean
  • 11
  • 2
  • Does this answer your question? [ImportError: No module named PIL](https://stackoverflow.com/questions/8863917/importerror-no-module-named-pil) – ErdoganOnal Apr 28 '21 at 05:27

1 Answers1

0

open cmd and run those commands:

python3 -m pip install --upgrade pip
python3 -m pip install --upgrade Pillow
R3tr0
  • 62
  • 8
  • ok go to cmd and run the command ```python3```, what version it says? – R3tr0 Apr 28 '21 at 05:34
  • - When I ran command as "python3 -m pip insta..." it says: "Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases." so, I ran command as "python -m pip insta..." And it says as: It says "Requirement already satisfied: Pillow in c:\users\ng\anaconda3\lib\site-packages" and gives version number I have on my system of the respective items. In this case: pip: (21.1) Pillow: (8.2.0) – Shrez Ean Apr 28 '21 at 05:35
  • When I typed python3, it took me to Microsoft store and When I type python --version, it shows: Python 3.8.5 – Shrez Ean Apr 28 '21 at 05:37
  • ok what editor you using? – R3tr0 Apr 28 '21 at 05:38
  • Visual Studio Code – Shrez Ean Apr 28 '21 at 05:39
  • I just installed Python 3.9 from MS Store – Shrez Ean Apr 28 '21 at 05:40
  • can you try run the same code using cmd with the command ```python3 code.py``` – R3tr0 Apr 28 '21 at 05:40
  • ok write ```python -m pip install --upgrade pip``` and then run this command ```python -m pip install Pillow``` – R3tr0 Apr 28 '21 at 05:42
  • Same error as before: D:\College\Sem4\Human Computer Interaction\Full project\code here>python3 Home.py Traceback (most recent call last): File "D:\College\Sem4\Human Computer Interaction\Full project\code here\Home.py", line 3, in from PIL import ImageTk, Image ModuleNotFoundError: No module named 'PIL' – Shrez Ean Apr 28 '21 at 05:42
  • if that dosent work, do the first commands i gave you using ```python3 ...``` and it suppose to work – R3tr0 Apr 28 '21 at 05:43
  • DAMN!! It works now.. Thanks man... But I am facing another issue, when I try to run it with python3 Home.py it runs, but when I try to run it with "run button" on top-right corner of VS Code, it shows as error as before... "PIL Module not found" error. Is that something you can help me with too ?? – Shrez Ean Apr 28 '21 at 05:49
  • you need to reconfigure the python env in visual studio code, adding a link: https://code.visualstudio.com/docs/python/environments , good luck! – R3tr0 Apr 28 '21 at 05:50