[英]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)
我在 Stackoverflow 上读到 PIL 不再维护。 但是,没有问题回答了我的问题: ImportError: No module named PIL
您可能已经在与您正在使用的 Python 安装不同的 Python 安装中安装 Pillow。 pip
和python
相互关联。 让我们先确定您正在使用哪些命令。
Q1 - 您使用什么命令来运行 Python 脚本?
启动 Python 脚本时使用什么命令? 或者,如果您使用图形 IDE,例如VS Code 、 JetBeans 、 IDLE ,它使用什么命令来启动 Python?
可能的答案:
因此,如果答案是python3
,那么在答案的其余部分中, YOURPYTHON
将是python3
。
Q2 - 你使用什么命令来安装 Python 包?
你用什么命令来安装 Python 包?
可能的答案:
因此,如果答案是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
运行pip install image --user
然后它应该可以工作。
import PIL
from PIL import Image
或者
import PIL
from PIL import *
这应该可以解决您的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.