错误:无法在 Python 中为 gevent 构建轮子
ERROR: Could not build wheels for gevent in Python
要解决错误“Could not build wheels for gevent”,请运行
pip install --upgrade pip
命令升级您的pip
版本,安装先决条件并重新运行pip install gevent
命令。
Failed to build gevent ERROR: Could not build wheels for gevent, which is required to install pyproject.toml-based projects
首先,确保安装先决条件。
# 👇️ for Debian (Ubuntu) sudo apt-get install python3.10-dev linux-headers-virtual make gcc libtool # 👇️ for Fedora yum install python3-devel gcc kernel-devel kernel-headers make diffutils file # 👇️ for Alpine Linux apk add --virtual build-deps file make gcc musl-dev libffi-dev
您可以在gevent 的 pypi 页面的安装部分阅读有关先决条件的更多信息
。
错误的最常见原因是具有过时的版本pip
。
以下是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
现在pip
已经升级,尝试运行pip install gevent
命令。
pip install gevent pip3 install gevent python -m pip install gevent python3 -m pip install gevent # 👇️ for Anaconda conda install -c anaconda gevent
如果错误未解决,请同时升级setuptools
和wheel
软件包。
pip install --upgrade setuptools wheel pip3 install --upgrade setuptools wheel python3 -m pip install --upgrade setuptools wheel
升级后尝试重新运行该pip install
命令。setuptools
wheel
如果这没有帮助,请尝试使用该
选项运行pip install
命令。--upgrade
pip install gevent --upgrade pip3 install gevent --upgrade python -m pip install gevent --upgrade python3 -m pip install gevent --upgrade
如果错误未解决,请尝试安装带有
--no-cache-dir
禁用缓存选项的软件包。
pip install gevent --no-cache-dir pip3 install gevent --no-cache-dir
如果这没有帮助,请使用该--pre
选项来包括包的预发布和开发版本。
pip install gevent --pre pip3 install gevent --pre python -m pip install gevent --pre python3 -m pip install gevent --pre
该--pre
选项使其pip
包含包的预发布和开发版本。默认情况下pip
只查找稳定版本。
wheel
如果错误未解决,请尝试运行带选项的pip install
命令
。--no-use-pep517
pip install --no-use-pep517 gevent pip3 install --no-use-pep517 gevent python -m pip install --no-use-pep517 gevent python3 -m pip install --no-use-pep517 gevent
如果这没有帮助,请尝试安装另一个版本的gevent
.
pip install package==
您可以通过运行命令来检查软件包的可用版本
。
pip install gevent==
输出包含包的所有版本的元组,从最旧的版本到最新的版本。
选择另一个版本的包并尝试安装它。这是一个例子。
pip install gevent==22.8.0 pip3 install gevent==22.8.0
如果这没有帮助,请尝试创建一个虚拟环境。
Create a virtual environment #
To solve the “Could not build wheels for gevent” error:
- Create a virtual environment.
- Activate the virtual environment.
- Run the
pip install
command with the virtual environment active.
# 👇️ 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 # 👇️ install the specific package in the virtual environment pip install gevent
If the python3 -m venv venv
command doesn’t work, try the following 2
commands:
python -m venv venv
py -m venv venv
Make sure to use the correct command to activate your virtual environment
depending on your operating system and your shell.
Your virtual environment will use the version of Python that was used to create
it.
Try running pip install in verbose mode #
If none of the suggestions helped, try running the pip install
command in
verbose mode.
pip install gevent -vvv pip3 install gevent -vvv python -m pip install gevent -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.
Check if your Python version is supported by the package #
The error “ERROR: Could not build wheels for gevent” is sometimes caused when
the package you are trying to install doesn’t have available wheels
for your
version of Python.
You can check your Python version with the python --version
command.
python --version
You can check if a package has wheels available for a specific Python version in
the Download files section of the
package’s pypi page.
cp310
in the name of a file under “Built Distributions” means Python version 3.10 is supported for the specific operating system.If the .whl
files are not available for your version of Python, you can
download an older version.
You can download a specific Python version that is supported by the package if
the package doesn’t support the latest Python version.
Different versions are available in the
“Looking for a specific release” table.
Make sure to tick the following options if you get prompted:
- Install launcher for all users (recommended)
- Add Python to PATH (this adds Python to your PATH environment variable)
Conclusion #
To solve the error “Could not build wheels for gevent”, run the
pip install --upgrade pip
command to upgrade your pip
version, install the
prerequisites and rerun the pip install gevent
command.