3

when I run the following

from tkinter import *
from PIL import ImageTk, Image




root.mainloop()

I got

Traceback (most recent call last):
  File "image_viewer.py", line 2, in <module>
    from PIL import ImageTk, Image
ImportError: No module named PIL

but I already install Pillow and everything is fine.

PCM
  • 2,692
  • 2
  • 7
  • 29
nono.qwerty28
  • 51
  • 1
  • 1
  • 2
  • 3
    If "__everything is fine__", what is your question now – PCM Jul 19 '21 at 10:44
  • 1
    Maybe you have different versions of Python on your computer and installed Pillow for the wrong one. – Matthias Jul 19 '21 at 10:45
  • 1
    Does this answer your question? [How to install PIL with pip on Mac OS?](https://stackoverflow.com/questions/20060096/how-to-install-pil-with-pip-on-mac-os) – Educorreia Jul 19 '21 at 10:46
  • If you're using PyCharm then you have to install modules through the PyCharm application. Also, it could be a version thing. Try `pip3 install Pillow` and check out https://www.jetbrains.com/help/pycharm/installing-uninstalling-and-upgrading-packages.html#packages-tool-window – Thomas Jul 19 '21 at 12:28

2 Answers2

12

Use Pillow which is the "new" or the replacement of PIL, but has the same-named modules to preserve compatibility:

pip install pillow

Also, as suggested in the comments, maybe you are just using the wrong python binary, try to check if you're in/out of a virtual environment or check differences between python vs python3 vs python2 on your system:

python -m pip list
python2 -m pip list
python3 -m pip list
Peter Badida
  • 10,502
  • 9
  • 40
  • 84
0

If you are sure that you already installed pillow use this command pip install pillow --upgrade, then you can use the command pip freeze to list all modules that have been installed.