无法安装PIL包

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

我已尽我所能并在互联网上找到了。我需要下载枕头。我在 PyCharm 终端中运行

pip install Pillow
,经过检查,它确实已安装,但当我尝试在代码中使用它时,它似乎无法识别它。

enter image description here

enter image description here

enter image description here

我正在使用 tkinter,最近开始使用 python 编程,所以我是一个新手。我遇到了一个与图像相关的问题,并了解到我应该尝试 PIL。当我将鼠标悬停在代码中的 PIL 上并尝试安装它时(即使它已经按照终端安装),我收到错误。将不胜感激您的帮助:D

python tkinter python-imaging-library
1个回答
0
投票

当你跑步时:

pip show pillow

它告诉您它在您的主目录下的某个“venv”中安装了 Pillow,即

/Users/raza/Downloads/pomodoro-start/venv/lib/python3.10/site-packages
。这意味着
venv
中的 Python 将在那里查找包。


当您在 IDE 中运行 Python 时,它会告诉您它正在某处

/System/Library
下运行 Python 解释器,特别是在
/Library/Developer/CommandLineTools/usr/bin/python3
处。该 Python 解释器将在与其包所在的目录非常接近的目录中查找。

如果运行以下命令,您同样可以看到此信息:

import sys

print(sys.executable) # show which Python we are running
print(sys.path)       # show where it is looking for packages

因此,总而言之,您将 Pillow 安装在位置 A(

venv
中的
/Users/raza/...
),但 PyCharm 中的 Python 解释器正在位置 B (
/System/Library/...
) 中寻找它。


为了修复它,您有几个选择:

  • 将 Pillow 安装到 Python 所在的位置,或者
  • 告诉您的 IDE 使用安装 Pillow 的 Python。

所以,对于上面的第一个选项...

您的 IDE 在

/Library/Developer/CommandLineTools/usr/bin/python3
使用 Python,因此如果您想为该解释器安装 Pillow,请使用:

# Install Pillow
/Library/Developer/CommandLineTools/usr/bin/python3 -m pip install Pillow

# Check where it was installed
/Library/Developer/CommandLineTools/usr/bin/pip show pillow

对于第二个选项(我不知道或不使用 PyCharm),您需要转到 PyCharm 设置中的某个位置并告诉它使用

/Users/raza/Downloads/pomodoro-start/venv/lib/python3.10
或附近的 Python 解释器。

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