0

I have Pillow installed successfully on my Mac, but when I type in

from PIL import Image

I get an error: "Unable to import 'PIL'

I'm using VSCode by the way. Anyone know how to fix this? I've looked through almost every stack overflow post, but can't seem to figure it out. I tried uninstalling and reinstalling, deleting PIL, etc. I have Pillow-7.1.2 by the way.

Katherine
  • 143
  • 2
  • 5
  • Check workspace settings, where is your python executable, and whether it corresponds to where Pillow is installed. – paiv Jun 02 '20 at 18:42
  • This could be a problem with pip and pip3. See https://stackoverflow.com/questions/40832533/pip-or-pip3-to-install-packages-for-python-3#:~:text=As%20you%20see%20they%20are,operate%20on%20the%20Python3%20environment. – KDD2020 Jun 02 '20 at 18:43
  • @KDD2020 just checked, pip is the same as pip3 for me – Katherine Jun 02 '20 at 18:46
  • So I figured out it is an issue with VS Code, not the installation. How can I fix that? – Katherine Jun 02 '20 at 19:48

1 Answers1

2

If you installed Pillow with:

pip install pillow

then you can find where it is installed with:

pip show pillow

Sample Output

Name: Pillow
Version: 7.1.2
Summary: Python Imaging Library (Fork)
Home-page: https://python-pillow.org
Author: Alex Clark (PIL Fork Author)
Author-email: aclark@python-pillow.org
License: HPND
Location: /usr/local/lib/python3.7/site-packages     <--- HERE

Of course, if you installed with:

pip3 install pillow

you will need:

pip3 show pillow

Now go to your Python interpreter and check where it is looking for packages and you will surely work out the problem:

python3 -c "import sys; print(sys.path)" | tr , '\n'

Samnple output

[
'/usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python36.zip'
'/usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python3.6'
'/usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/lib-dynload'
'/usr/local/lib/python3.6/site-packages'
'/usr/local/Cellar/numpy/1.13.3/libexec/nose/lib/python3.6/site-packages']

Of course, if you start Python with python rather than python3, you will need:

python -c "import sys; print(sys.path)" | tr , '\n'

Finally, go to your Terminal and find out what your shell actually runs when you enter python by running:

type python            # or "type python3" if you normally enter "python3"

Now go in your IDE and see which Python that runs:

import sys
print(sys.executable)
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432