简体   繁体   English

找不到模块PIL,但已安装并更新

[英]no module found PIL but it is installed and up2date

I am trying to download images with scrapy on mac os X and it returns the following error msg: 我试图在Mac OS X上下载有刮痕的图像,它返回以下错误消息:

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 通过自制软件安装Python ist

PIP via sudo: sudo pip install image 通过sudo进行PIP: 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? 任何想法如何解决?

Which version of Python do you want to use? 您要使用哪个版本的Python? 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 . 您似乎声称您是通过自制软件安装的Python,但是您使用的是Apple在/usr/bin/python提供的Python 2.7,这就是为什么pip安装在/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 . 如果要使用自制 Python和pip ,则需要运行/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 . 通常,在/anywhere/LOCAL/anywhere中查找或安装的所有内容都是homebrew Anything that uses /usr/bin or /Library/anywhere will be Apple-supplied. 任何使用/usr/bin/Library/anywhere都将由Apple提供。


If you want to know which actual command you are running, use type like this: 如果您想知道正在运行的实际命令,请使用如下type

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/... 所以这告诉我,在我的机器上, python/usr/local/...的一个,它必须来自自制软件,因为它包含/.../LOCAL/...

Your python is currently /usr/bin/python . 您的python当前是/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 . 如果你想使用一个自制软件 ,你需要在你登录的个人资料更改PATH,把/usr/local/opt/python/libexec/bin 之前 /usr/bin Eg: 例如:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM