Python 未找到模块PIL,但已安装并通过yum或up2date验证

Python 未找到模块PIL,但已安装并通过yum或up2date验证,python,macos,scrapy,pip,python-imaging-library,Python,Macos,Scrapy,Pip,Python Imaging Library,我试图在mac os X上下载带有scrapy的图像,它返回以下错误消息: 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-

我试图在mac os X上下载带有scrapy的图像,它返回以下错误消息:

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)
让我们尝试安装映像包:

$ 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)
更新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

通过sudo的PIP:sudo PIP安装映像

还尝试:

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
以及:

更多信息:

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: 

有没有办法解决这个问题?

您想使用哪个版本的Python?您似乎声称自己是通过自制软件安装Python的,但您使用的是苹果在/usr/bin/Python中提供的Python 2.7,这就是为什么pip要安装在/Library/Python/2.7中

如果要使用自制Python和pip,需要运行/usr/local/opt/Python/libexec/bin/Python。如果运行以下命令,您可以看到所有这些信息:

brew info python
通常,在/anywhere/LOCAL/anywhere中查找或安装的任何内容都将是自制的。任何使用/usr/bin或/Library/anywhere的软件都将由苹果提供

如果要知道正在运行的实际命令,请使用以下类型:

type python
python is hashed (/usr/local/opt/python/libexec/bin/python)
这告诉我,在我的机器上,python是/usr/local/中的一个。。。它必须来自自制,因为它包含/../LOCAL/

您的python当前为/usr/bin/python。如果您想使用自制的,您需要更改登录配置文件中的路径,并将/usr/local/opt/python/libexec/bin放在/usr/bin之前。例如:

然后启动一个新的终端,以便使用新的配置文件运行

请注意区别:

# 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

我执行了导出命令,现在我在同一个终端中获得了3.7.1版本。然而,如果我打开一个新的终端,我得到的是旧版本。在运行3.7.1的终端中,同样的问题也发生了,我将输出作为附加信息发布到问题中。在我看来还可以,但仍然是相同的错误。您需要编辑您的登录配置文件,并在其中进行导出-它可能是$HOME/.profile,然后它将在您每次登录时设置路径。当python-V和pip-V告诉您自制版本时,您将需要运行pip-install-pillow,因为目前您已经安装了适用于applepythonv2.7的pillow
export PATH=/usr/local/opt/python/libexec/bin:$PATH
# 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