How to Install Pil with Pip?

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.

4

2 Answers

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

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Sophia Al-Mansoor

Sophia Al-Mansoor

Global Business & E-Commerce Reporter

Sophia analyzes international trade, startup ecosystems, retail transformation, and supply chain logistics for modern digital publications.

Share this article
Twitter Facebook Pinterest