尽管安装了 PIP,Python Pillow(或 PIL)仍无法工作

问题描述 投票:0回答:3

我正在关注文档:https://pillow.readthedocs.io/en/stable/

我用 pip 成功安装了 Pillow。但是,当我尝试导入

Image
函数时,我可以:

a) 仅从 PIL 导入 b) 只得到没有模块的错误

PIL
c) 出现没有模块的错误
Pillow

这是消息(当我尝试使用 Pillow 而不是 PIL 时,会发生同样的情况):

from PIL import Image
ModuleNotFoundError: No module named 'PIL'

这是我已经用 pip 安装它的证据:

Requirement already satisfied: Pillow in c:\python310\lib\site-packages (8.4.0)

我在 Stackoverflow 上读到 PIL 不再维护。但是,没有任何问题回答我的问题: 导入错误:没有名为 PIL 的模块

python python-imaging-library
3个回答
6
投票

您可能在与您正在使用的 Python 安装不同的 Python 安装中安装了 Pillow。

pip
python
彼此相连。让我们首先确定您使用的命令。


Q1 - 您使用什么命令来运行Python脚本?

启动Python脚本时使用什么命令?或者,如果您使用图形 IDE,例如VS CodeJetBeansIDLE,它用什么命令来启动Python?

可能的答案:

  • 蟒蛇
  • python-2.7
  • python3

因此,如果答案是

python3
,那么答案的其余部分
YOURPYTHON
将是
python3


问题2 - 你使用什么命令来安装Python包?

使用什么命令来安装Python包?

可能的答案:

  • 点-2.7
  • pip3

因此,如果答案是

pip3
,那么答案的其余部分
YOURPIP
将是
pip3


您已使用

pip
安装到 Python 310 安装中,您可以在 “满足要求” 消息中看到这一点,或者通过运行:

YOURPIP -V                # quick version check
YOURPIP show pillow       # more detail as to location
YOURPIP debug             # lots of detail about how pip is set up

现在的问题是你使用的是哪种Python?它在看哪里?

YOURPYTHON -V                                            # quick version check
YOURPYTHON -c "import sys; print(sys.executable)"        # where is my Python interpreter?
YOURPYTHON -c "import sys; print('\n'.join(sys.path))"   # where does it look for packages?

一般来说,如果您使用

python
,您可能应该使用
pip
。但如果您使用
python3
,您可能应该使用
pip3
以确保您安装到解释器正在查找的同一位置。

当您键入如下命令时,您可以获得有关实际运行的信息:

which python    # works on macOS, Linux and Windows
type python     # works on macOS and Linux and is preferable

1
投票

运行

pip install image --user
然后它应该可以工作了。


0
投票

当我使用命令

py [filename]
时,它不起作用,但当我尝试
python [filename]
时,它工作得很好,所以我想你最好使用
python
命令,而不是缩写的
py

© www.soinside.com 2019 - 2024. All rights reserved.