【问题标题】:no module found PIL but it is installed and up2date没有找到 PIL 模块,但它已安装并更新
【发布时间】:2019-05-02 09:40:58
【问题描述】:

我正在尝试在 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 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

通过 sudo 进行 PIP:sudo pip install image

也试过了:

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

与:

brew unlink python && brew link python

更多信息:

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 macos scrapy pip python-imaging-library


【解决方案1】:

您想使用哪个版本的 Python?您似乎声称您通过 homebrew 安装了 Python,但您使用的是 Apple 在 /usr/bin/python 中提供的 Python 2.7,这就是 pip 在 /Library/Python/2.7 中安装的原因。

如果你想使用 homebrew Python 和pip,你需要运行/usr/local/opt/python/libexec/bin/python。如果你运行,你可以看到所有这些信息:

brew info python

一般来说,在/anywhere/LOCAL/anywhere 中查看或安装的任何内容都是homebrew。任何使用 /usr/bin/Library/anywhere 的东西都将由 Apple 提供。


如果您想知道您正在运行的实际命令,请像这样使用type

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

这告诉我,在我的机器上,python/usr/local/... 中的那个,它必须来自 homebrew,因为它包含 /.../LOCAL/...

您的python 目前是/usr/bin/python。如果你想使用 homebrew 之一,你需要在你的登录配置文件中更改你的 PATH 并输入 /usr/local/opt/python/libexec/bin before /usr/bin。例如:

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

【讨论】:

  • 我执行了导出命令,现在我在同一个终端中获得了 3.7.1 版本。但是,如果我打开一个新终端,我会得到旧版本。在运行 3.7.1 的终端中发生了同样的问题,我将输出作为附加信息发布到问题中。对我来说看起来不错,但仍然是同样的错误。
  • 您需要编辑您的登录配置文件,并在那里执行export - 它可能是$HOME/.profile,然后它会在您每次登录时设置路径。当您获得python -V pip -V 告诉你 homebrew 版本,你需要运行 pip install pillow 因为目前你已经安装了 Pillow for Apple Python v2.7
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-04-26
  • 2021-01-31
  • 2012-03-05
  • 2020-12-25
  • 2020-06-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多