1

I'm on Windows 10 trying to update someone's file to Python 3. In any case, I cannot import Pillow with import PIL, despite having the proper version installed and having uninstalled and reinstalled the library. What can I do? How can I discover the source of the problem?

I briefly tried installing Python 2; I hope this did not mess up my system or anything.

UPDATE: This issue occurs only in the Thonny IDE, not in the Python shell or IDLE.

Lyndon Gingerich
  • 604
  • 7
  • 17
  • 1
    This could be because you have multiple Python 3's installed. Trying installing it with the python command you're using to run your script `python3 -m pip install pillow` or `python3.8 -m pip install pillow` or whatever. – Boris Verkhovskiy Dec 31 '20 at 00:30
  • @Boris Thonny uses Python 3.7.9, whereas I use Python 3.9 otherwise. Could this be a problem? – Lyndon Gingerich Dec 31 '20 at 00:32
  • 1
    yes. If you installed the module using Python 3.9's `pip` then it will not be available in Python 3.7 and vice-versa. Modules are not (usually) shared across Python installations. You need to figure out [how to install the module with the Python version Thonny is using](https://github.com/thonny/thonny/wiki/InstallingPackages), or change Thonny to also use Python 3.9. – Boris Verkhovskiy Dec 31 '20 at 00:36
  • @Boris Thank you for your help. I think I'll skip the headache of figuring out how to install libraries for different versions of Python on Windows and switch to Wing. – Lyndon Gingerich Dec 31 '20 at 01:13
  • @Boris You solved my question with comments. If you post your answer, I'll accept it. – Lyndon Gingerich Dec 31 '20 at 01:18
  • 1
    I recommend using [VS Code](https://code.visualstudio.com/download) (or [Pycharm](https://www.jetbrains.com/pycharm/) if you can afford it) for developing in Python. – Boris Verkhovskiy Dec 31 '20 at 01:30

1 Answers1

1

As you said

This issue occurs only in the Thonny IDE, not in the Python shell or IDLE

Thonny uses Python 3.7.9, whereas I use Python 3.9 otherwise

Your issue happens almost certainly because you installed Pillow for Python 3.9 and not for 3.7. Judging from Thonny's documentation on installing packages you should be able to open a shell and do

python3.7 -m pip install Pillow

and then you'll be able to import Pillow in Thonny as well.

You can confirm which Python version the pip3 command is using using pip3 --version. For example on my Ubuntu system I have the system Python 3.8 and also Python 3.9, so I get this:

$ pip3 --version
pip 20.3.3 from /usr/local/lib/python3.9/dist-packages/pip (python 3.9)
$ python3.8 -m pip --version
pip 20.3.3 from /usr/local/lib/python3.8/dist-packages/pip (python 3.8)
Boris Verkhovskiy
  • 14,854
  • 11
  • 100
  • 103