Python 尽管安装了 PIP,Pillow(或 PIL)仍无法正常工作
Python Pillow (or PIL) not working despite PIP installation
我正在关注文档: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)
我在 Whosebug 上看到 PIL 不再维护。但是,没有问题回答我的问题:
ImportError: No module named PIL
运行 pip install image --user
然后它应该工作。
您可能已将 Pillow 安装在与您正在使用的不同的 Python 安装中。 pip
和 python
相互链接。让我们先确定您正在使用的命令。
Q1 - 你对 运行 Python 脚本使用什么命令?
启动 Python 脚本时使用什么命令?或者,如果您使用图形 IDE,例如VS Code,JetBeans,IDLE,它用什么命令启动Python?
可能的答案:
- python
- python-2.7
- python3
因此,如果答案是 python3
,那么答案的其余部分 YOURPYTHON
将是 python3
。
Q2 - 您使用什么命令安装 Python 软件包?
你使用什么命令来安装 Python 包?
可能的答案:
- 点
- pip-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
来确保你安装到你的解释器正在寻找的同一个地方。
当您键入如下命令时,您可以获得有关实际 运行ning 的信息:
which python # works on macOS, Linux and Windows
type python # works on macOS and Linux and is preferable
我正在关注文档: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)
我在 Whosebug 上看到 PIL 不再维护。但是,没有问题回答我的问题: ImportError: No module named PIL
运行 pip install image --user
然后它应该工作。
您可能已将 Pillow 安装在与您正在使用的不同的 Python 安装中。 pip
和 python
相互链接。让我们先确定您正在使用的命令。
Q1 - 你对 运行 Python 脚本使用什么命令?
启动 Python 脚本时使用什么命令?或者,如果您使用图形 IDE,例如VS Code,JetBeans,IDLE,它用什么命令启动Python?
可能的答案:
- python
- python-2.7
- python3
因此,如果答案是 python3
,那么答案的其余部分 YOURPYTHON
将是 python3
。
Q2 - 您使用什么命令安装 Python 软件包?
你使用什么命令来安装 Python 包?
可能的答案:
- 点
- pip-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
来确保你安装到你的解释器正在寻找的同一个地方。
当您键入如下命令时,您可以获得有关实际 运行ning 的信息:
which python # works on macOS, Linux and Windows
type python # works on macOS and Linux and is preferable