Katherine
Katherine

Reputation: 153

Using Pillow for python 3.7 Mac OS?

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.

Upvotes: 0

Views: 611

Answers (1)

Mark Setchell
Mark Setchell

Reputation: 207978

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)

Upvotes: 2

Related Questions