找不到满足 PIL 要求的版本

找不到满足 PIL 要求的版本

Could not find version that satisfies the requirement PIL

当我们尝试 pip 安装包时出现错误“找不到满足要求 PIL 的版本” PIL

要解决该错误,请安装 Pillow,它是 的维护分支PIL,可用作直接替代品。

找不到满足 pil 要求的版本

ERROR: Could not find a version that satisfies the requirement PIL (from versions: none) ERROR: No matching distribution found for PIL

在安装 Pillow 之前卸载 PIL

在项目的根目录中打开终端并安装
Pillow模块,它是 PIL 的维护分支。

如果已经PIL安装,请务必先将其卸载,因为这两个包不能共存于同一环境中。

# 👇️ Before installing Pillow, uninstall PIL. pip uninstall PIL # 👇️ in a virtual environment or using Python 2 pip install Pillow # 👇️ for python 3 (could also be pip3.10 depending on your version) pip3 install Pillow # 👇️ if you get permissions error sudo pip3 install Pillow # 👇️ if you don't have pip in your PATH environment variable python -m pip install --upgrade Pillow # 👇️ for python 3 (could also be pip3.10 depending on your version) python3 -m pip install --upgrade Pillow # 👇️ for Anaconda conda install -c conda-forge pillow

请注意,我们确保PIL在安装Pillow.

安装Pillow 包后,尝试按如下方式导入它。

主程序
from PIL import Image im = Image.open("hopper.ppm") print(im.format, im.size, im.mode)

升级你的版本pip

如果错误仍然存​​在,请升级 pip并尝试重新运行pip install Pillow命令。

pip以下是在所有操作系统上升级的命令。

哪个命令有效取决于您的操作系统和 Python 版本。

# 👇️ if you have pip already installed pip install --upgrade pip # 👇️ if your pip is aliased as pip3 (Python 3) pip3 install --upgrade pip # 👇️ if you don't have pip in your PATH environment variable python -m pip install --upgrade pip # 👇️ if you don't have pip in your PATH environment variable python3 -m pip install --upgrade pip # 👇️ if you have easy_install easy_install --upgrade pip # 👇️ if you get a permissions error sudo easy_install --upgrade pip # 👇️ if you get a permissions error when upgrading pip pip install --upgrade pip --user # 👇️ upgrade pip scoped to the current user (if you get permissions error) python -m pip install --user --upgrade pip python3 -m pip install --user --upgrade pip # 👇️ Installing directly from get-pip.py (MacOS and Linux) curl https://bootstrap.pypa.io/get-pip.py | python # 👇️ if you get permissions issues curl https://bootstrap.pypa.io/get-pip.py | sudo python # 👇️ alternative for Ubuntu/Debian sudo apt-get update && apt-get upgrade python-pip # 👇️ alternative for Red Hat / CentOS / Fedora sudo yum install epel-release sudo yum install python-pip sudo yum update python-pip

如果你收到错误“ModuleNotFoundError: No module named ‘pip’ in Python”,请查看我的另一篇文章:

pip install Pillow升级后尝试运行命令pip

pip install Pillow --upgrade pip3 install Pillow --upgrade python3 -m pip install Pillow --upgrade

检查 Pillow 是否支持你的 Python 版本

如果这没有帮助,请检查 Pillow 是否支持您的 Python 版本。

Pillow软件包支持 Python 3.7+ 版本。

你可以打开Pillow 的 pypi 页面,在左侧边栏Meta>
下查看支持的 Python 版本
Requires

枕头支持的 python 版本

您可以使用python --version命令检查您的 Python 版本。

python --version python3 --version

获取 python 版本

如果您的 Python 版本低于 3.7,请从官方 python.org 网站下载最新版本并运行安装程序。

如果出现提示,请确保勾选以下选项:

  • 为所有用户安装启动器(推荐)
  • 将 Python 添加到 PATH(这会将 Python 添加到您的 PATH 环境变量)

一旦您拥有支持范围内的 Python 版本,请尝试安装Pillow.

pip install Pillow --upgrade pip3 install Pillow --upgrade python3 -m pip install Pillow --upgrade

如果这没有帮助,请尝试在范围为 Python 3 的虚拟环境中安装该包。

尝试在虚拟环境中安装包

另一件可能有帮助的事情是创建一个虚拟环境(如果您还没有的话)。

# 👇️ use correct version of Python when creating VENV python3 -m venv venv # 👇️ activate on Unix or MacOS source venv/bin/activate # 👇️ activate on Windows (cmd.exe) venv\Scripts\activate.bat # 👇️ activate on Windows (PowerShell) venv\Scripts\Activate.ps1 # 👇️ Upgrade pip pip install --upgrade pip # 👇️ install Pillow in virtual environment pip install Pillow

确保根据您的操作系统使用正确的激活命令。

您的虚拟环境将使用用于创建它的 Python 版本。

如果这没有帮助,请尝试将命令的范围限定为特定用户。

--user选项将包安装在用户的主目录中。

pip install Pillow --user pip3 install Pillow --user python3 -m pip install Pillow --user
The command basically installs the package scoped to the specific user, not for the entire system. This helps with permission issues.

If you get a permissions error, try running the command with the --user flag
or with sudo.

shell
sudo pip install Pillow sudo pip3 install Pillow sudo python3 -m pip install Pillow

If that didn’t help, try running the command in verbose mode.

# Try running pip install Pillow in verbose mode

If none of the suggestions helped, try running the pip install command in
verbose mode.

shell
pip install Pillow -vvv pip3 install Pillow -vvv python -m pip install Pillow -vvv

The -v option stands for verbose mode and can be used up to 3 times.

When the pip install command is run in verbose mode, the command shows more
output and how the error occurred.