0

I am trying to download images with scrapy on mac os X and it returns the following error msg:

ModuleNotFoundError: No module named 'PIL'
$ pip install image
Requirement already satisfied: image in /Library/Python/2.7/site-packages (1.5.27)
Requirement already satisfied: django in /Library/Python/2.7/site-packages (from image) (1.11.16)
Requirement already satisfied: pillow in /Library/Python/2.7/site-packages (from image) (5.3.0)
Requirement already satisfied: pytz in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from django->image) (2013.7)

Lets try to install the image package:

$ pip install image
Reqfuirement already satisfied: image in /Library/Python/2.7/site-packages (1.5.27)
Requirement already satisfied: django in /Library/Python/2.7/site-packages (from image) (1.11.16)
Requirement already satisfied: pillow in /Library/Python/2.7/site-packages (from image) (5.3.0)
Requirement already satisfied: pytz in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from django->image) (2013.7)

Update pip?

pip install --upgrade pip
Requirement already up-to-date: pip in /Library/Python/2.7/site-packages/pip-18.1-py2.7.egg (18.1)

Python ist installe via homebrew

PIP via sudo: sudo pip install image

Also tried:

easy_install pip
Password:
Searching for pip
Best match: pip 18.1
Processing pip-18.1-py2.7.egg
pip 18.1 is already the active version in easy-install.pth
Installing pip script to /usr/local/bin
Installing pip2.7 script to /usr/local/bin
Installing pip2 script to /usr/local/bin

Using /Library/Python/2.7/site-packages/pip-18.1-py2.7.egg
Processing dependencies for pip
Finished processing dependencies for pip

AND:

brew unlink python && brew link python

More info:

File "/usr/local/lib/python3.7/site-packages/scrapy/pipelines/images.py", line 15, in <module>
    from PIL import Image
ModuleNotFoundError: No module named 'PIL'

MBP:bid user$ type python
python is hashed (/usr/local/opt/python/libexec/bin/python)

MBP:bid user$ /usr/local/opt/python/libexec/bin/pip show pip
Name: pip
Version: 18.1
Summary: The PyPA recommended tool for installing Python packages.
Home-page: https://pip.pypa.io/
Author: The pip developers
Author-email: pypa-dev@groups.google.com
License: MIT
Location: /usr/local/lib/python3.7/site-packages
Requires: 
Required-by: 

Any ideas how to fix that?

merlin
  • 2,717
  • 3
  • 29
  • 59
  • 1
    Possible duplicate of [Installing PIL with pip](https://stackoverflow.com/questions/20060096/installing-pil-with-pip) – parthagar Nov 30 '18 at 09:03

1 Answers1

1

Which version of Python do you want to use? You seem to claim you installed Python via homebrew but you are using Python 2.7 as supplied by Apple in /usr/bin/python and that is why pip is installing in /Library/Python/2.7.

If you want to use homebrew Python and pip you need to be running /usr/local/opt/python/libexec/bin/python. You can see all this information if you run:

brew info python

In general, anything that looks in or is installed in /anywhere/LOCAL/anywhere will be homebrew. Anything that uses /usr/bin or /Library/anywhere will be Apple-supplied.


If you want to know which actual command you are running, use type like this:

type python
python is hashed (/usr/local/opt/python/libexec/bin/python)

So that tells me that, on my machine, python is the one in /usr/local/... which must be from homebrew because it contains /.../LOCAL/...

Your python is currently /usr/bin/python. If you want to use the homebrew one, you need to change your PATH in you login profile and put /usr/local/opt/python/libexec/bin before /usr/bin. E.g.:

export PATH=/usr/local/opt/python/libexec/bin:$PATH

Then start a new Terminal so that you are running with the new profile.


Note the difference:

# Run the old Apple-supplied Python
/usr/bin/python -V
Python 2.7.10

# Run the shiny new homebrew Python
/usr/local/opt/python/libexec/bin/python -V
Python 3.7.1

# Run the homebrew pip - that installs into /something/LOCAL/something - sure sign it is not Apple's
/usr/local/opt/python/libexec/bin/pip show pip
Name: pip
Version: 18.1
Summary: The PyPA recommended tool for installing Python packages.
Home-page: https://pip.pypa.io/
Author: The pip developers
Author-email: pypa-dev@groups.google.com
License: MIT
Location: /usr/local/lib/python3.7/site-packages
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
  • I did the export command and now I get the 3.7.1 version in the same terminal. However if I open a new terminal, I am getting the old version. Within the terminal running 3.7.1 the same problem occures, I posted the output as addtional info to the question. Looks OK to me, but still the same errror. – merlin Nov 30 '18 at 12:09
  • You need to edit your login profile, and do the `export` in there too - it is probably `$HOME/.profile` then it will set the PATH every time you log in. When you get `python -V` and `pip -V` telling you the **homebrew** version, you will need to run `pip install pillow` because, at the moment, you have installed Pillow for Apple Python v2.7 – Mark Setchell Nov 30 '18 at 13:05