gpt4 book ai didi

python - 没有名为 Pillow 的模块

转载 作者:行者123 更新时间:2023-12-01 07:57:16 26 4
gpt4 key购买 nike

在 Windows 10 pro 上,我正在运行安装了 python 和 jupyter 的 docker 镜像。我可以启动 docker 镜像,然后从该 shell 启动 jupyter 笔记本。 python2 和 python3 内核均可用。 PIL 和 Pillow 已安装,但我无法导入它们。见下文:

(我用双星号指示了每个 jupyter 单元格的内容。

每个单元格的结果简单地跟随在其下方)

**!pip install Image**
Requirement already satisfied: Image in /usr/local/lib/python3.6/dist-packages (1.5.27)
Requirement already satisfied: pillow in /usr/lib/python3/dist-packages (from Image) (5.1.0)
Requirement already satisfied: django in /usr/local/lib/python3.6/dist-packages (from Image) (2.2)
Requirement already satisfied: sqlparse in /usr/local/lib/python3.6/dist-packages (from django->Image) (0.3.0)
Requirement already satisfied: pytz in /usr/lib/python3/dist-packages (from django->Image) (2018.3)
You are using pip version 19.0.3, however version 19.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

**!pip install Pillow**
Requirement already satisfied: Pillow in /usr/lib/python3/dist-packages (5.1.0)
You are using pip version 19.0.3, however version 19.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

**!python -m pip install pillow**
Requirement already satisfied: pillow in /usr/lib/python3/dist-packages (5.1.0)
You are using pip version 19.0.3, however version 19.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.


**import PIL**
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-7-70d569469e06> in <module>()
----> 1 import PIL

ImportError: No module named PIL


**import PIL.Image**
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-8-df3f6661ddbf> in <module>()
----> 1 import PIL.Image

ImportError: No module named PIL.Image


**import pillow**
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-11-e32915389b2c> in <module>()
----> 1 import pillow

ImportError: No module named pillow

但是当我退出笔记本并在正在运行的 docker 容器中启动交互式 python session 时,很容易找到 PIL:

root@7092fc2336d3:/# python
Python 3.6.7 (default, Oct 22 2018, 11:32:17)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import PIL
>>>

最佳答案

这很奇怪。事实证明,jupyter 中的 pip 安装在 python3 站点包中,但 jupyter 笔记本中的 python 正在 python2 站点包中查找。所以当我像这样在 jupyter 单元中安装枕头时

!/usr/bin/python2.7 -m pip install Pillow

现在可以了

import PIL.Image

关于python - 没有名为 Pillow 的模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55908229/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com