python - 尽管安装了 PIP,Python Pillow(或 PIL)仍无法正常工作
问题描述
我正在关注文档: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 不再维护。但是,没有问题回答我的问题: ImportError: No module named PIL
解决方案
您可能已经在与您正在使用的 Python 安装不同的 Python 安装中安装了 Pillow。pip
并且python
相互关联。让我们先确定您正在使用哪些命令。
Q1 - 你使用什么命令来运行 Python 脚本?
启动 Python 脚本时使用什么命令?或者,如果您使用图形 IDE,例如VS Code、JetBeans、IDLE,它使用什么命令来启动 Python?
可能的答案:
- Python
- python-2.7
- 蟒蛇3
所以,如果答案是python3
,那么剩下的答案YOURPYTHON
就是python3
。
Q2 - 你使用什么命令来安装 Python 包?
你使用什么命令来安装 Python 包?
可能的答案:
- 点子
- 点子2.7
- 点子3
所以,如果答案是pip3
,那么剩下的答案YOURPIP
就是pip3
。
您已将 with 安装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
推荐阅读
- mysql - Laravel MySQL 数据透视表到列
- php - 在目录中创建新文件时在 Linux 中运行 Crontab
- r - 如何在R中融化数据框
- javascript - 是什么阻止我的 jquery 函数执行 ajax 脚本
- angular - 默认图像未显示,而 Angular 4 中的配置文件图像为空
- php - elseif 不能按预期在 php 中工作
- javascript - 在可拖动的div下获取文本(jquery)
- javascript - 做什么和意思是?
- tensorflow - 冻结 mobilenet_v2 (freeze_graph.py)
- javascript - 如何在 JS 中使用三元运算符进行返回?