错误:无法在 Python 中为 pycuda 构建轮子

错误:无法在 Python 中为 pycuda 构建轮子

ERROR: Could not build wheels for pycuda in Python

要解决“Could not build wheels for pycuda”错误,请运行
pip install --upgrade pip命令升级您的pip版本并重新运行
pip install pycuda命令。

错误无法为pycuda构建轮子

ERROR: Failed building wheel for pycuda Failed to build pycuda ERROR: Could not build wheels for pycuda, which is required to install pyproject.toml-based projects

首先,如果您使用的是 Linux,请安装先决条件。

# 👇️ Debian (Ubuntu) sudo apt-get install python3-dev # 👇️ CentOS, RHEL sudo yum install python3-devel # 👇️ Fedora sudo dnf install python3-devel # 👇️ openSUSE sudo zypper in python3-devel # 👇️ Alpine sudo apk add python3-dev # 👇️ Cygwin apt-cyg install python3-devel

错误的最常见原因是具有过时的版本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 pycuda命令。

pip install pycuda pip3 install pycuda python -m pip install pycuda python3 -m pip install pycuda # 👇️ for Anaconda conda install -c conda-forge pycuda

如果错误未解决,请同时升级setuptoolswheel软件包。

pip install --upgrade setuptools wheel pip3 install --upgrade setuptools wheel python3 -m pip install --upgrade setuptools wheel

升级后尝试重新运行该pip install命令setuptoolswheel

如果这没有帮助,请尝试使用该
选项运行
pip install命令。--upgrade

pip install pycuda --upgrade pip3 install pycuda --upgrade python -m pip install pycuda --upgrade python3 -m pip install pycuda --upgrade

如果错误未解决,请尝试安装带有
--no-cache-dir禁用缓存选项的软件包。

pip install pycuda --no-cache-dir pip3 install pycuda --no-cache-dir

如果这没有帮助,请使用该--pre选项来包括包的预发布和开发版本。

pip install pycuda --pre pip3 install pycuda --pre python -m pip install pycuda --pre python3 -m pip install pycuda --pre

--pre选项使其pip包含包的预发布和开发版本。默认情况下pip只查找稳定版本。

这有时会有所帮助,因为包的预发布版本可能适用于您的 Python 版本。 wheel

如果错误未解决,请尝试运行带选项的pip install命令
--no-use-pep517

pip install --no-use-pep517 pycuda pip3 install --no-use-pep517 pycuda python -m pip install --no-use-pep517 pycuda python3 -m pip install --no-use-pep517 pycuda

如果这没有帮助,请尝试安装另一个版本的pycuda.

pip install package==您可以通过运行命令来检查包的可用版本

pip install pycuda==

pip 列出包的所有可用版本

输出包含包的所有版本的元组,从最旧的版本到最新的版本。

选择另一个版本的包并尝试安装它。这是一个例子。

pip install pycuda==2021.1 pip3 install pycuda==2021.1

如果这没有帮助,请尝试创建一个虚拟环境。

创建虚拟环境

要解决“Could not build wheels for pycuda”错误:

  1. 创建一个虚拟环境。
  2. 激活虚拟环境。
  3. 在虚拟环境处于活动状态的情况下运行pip install命令。
# 👇️ 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 pycuda

如果该python3 -m venv venv命令不起作用,请尝试以下 2 个命令:

  • python -m venv venv
  • py -m venv venv

确保根据您的操作系统和 shell 使用正确的命令来激活您的虚拟环境。

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

检查包是否支持您的 Python 版本

当您尝试安装的包不适wheels用于您的 Python 版本时,有时会导致错误“Could not build wheels for pycuda”。

您可以在 pycuda 的 pypi 页面pycuda侧栏中的 Meta > Description 下查看 Python 版本
支持

If your version of Python isn’t supported by pycuda, you can download a
version in the supported range from the
official python.org website.

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)

Try running pip install in verbose mode #

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

shell
pip install pycuda -vvv pip3 install pycuda -vvv python -m pip install pycuda -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.

Conclusion #

要解决“Could not build wheels for pycuda”错误,请运行
pip install --upgrade pip命令升级您的pip版本并重新运行
pip install pycuda命令。