error: subprocess-exited-with-error × Preparing metadata (pyproject.toml) did no...
🚨 错误信息
Collecting PyQt6
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/96/03/e756f52e8b0d7bb5527baf8c46d59af0746391943bdb8655acba22ee4168/pyqt6-6.10.2.tar.gz (1.1 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.1/1.1 MB 5.8 MB/s 0:00:00
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing metadata (pyproject.toml) ... error
error: subprocess-exited-with-error
× Preparing metadata (pyproject.toml) did not run successfully.error: metadata-generation-failed
× Encountered error while generating package metadata.
╰─> PyQt6
🤖 AI解决方案
PyQt6 安装报错分析
错误翻译
原文:Preparing metadata (pyproject.toml) ... error
译文:准备元数据(pyproject.toml)时出现错误
原文:Encountered error while generating package metadata. ╰─> PyQt6
译文:生成包元数据时遇到错误。 ╰─> PyQt6
2.分析
这是安装 PyQt6 时遇到的常见问题,主要原因包括:
错误发生在 pip 尝试从源码包构建 PyQt6 的元数据阶段。
解决方案
方案一:使用预编译的二进制包(推荐)
bash
对于 Windows 用户
pip install PyQt6 --only-binary PyQt6或者从指定源安装预编译版本
pip install PyQt6 -i https://pypi.tuna.tsinghua.edu.cn/simple/
方案二:安装必要的编译依赖
Ubuntu/Debian 系统:
bash
sudo apt-get update
sudo apt-get install -y python3-dev build-essential
sudo apt-get install -y libgl1-mesa-dev libxcb-xinerama0-dev
macOS 系统:
bash
brew install pkg-config
brew install qt@6
Windows 系统:
安装 Microsoft C++ Build Tools:
方案三:尝试其他安装方式
bash
使用 conda(如果有 Anaconda/Miniconda)
conda install pyqt -c conda-forge或者直接安装 wheel 文件
先查看支持的平台和版本:https://pypi.org/project/PyQt6/#files
4.措施
bash
pip install --only-binary :all: 包名
bash
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
注意:如果以上方案都不能解决问题,可以考虑使用 PyQt5(相对更稳定)或改用其他 GUI 库如 Tkinter、wxPython 作为临时替代方案。