安装PyQt6时PyQt6-sip构建wheel失败,提示找不到兼容的Visual Studio安装
问题背景
我使用的Python版本是3.13.0,已经更新过pip,并且认为自己已经安装了Visual Studio,但在执行pip install PyQt6时遇到了以下错误:
pip install PyQt6 Collecting PyQt6 Using cached PyQt6-6.7.1-cp38-abi3-win_amd64.whl.metadata (2.1 kB) Collecting PyQt6-sip<14,>=13.8 (from PyQt6) Using cached PyQt6_sip-13.8.0.tar.gz (92 kB) Installing build dependencies ... done Getting requirements to build wheel ... done Preparing metadata (pyproject.toml) ... done Collecting PyQt6-Qt6<6.8.0,>=6.7.0 (from PyQt6) Using cached PyQt6_Qt6-6.7.3-py3-none-win_amd64.whl.metadata (551 bytes) Using cached PyQt6-6.7.1-cp38-abi3-win_amd64.whl (6.6 MB) Using cached PyQt6_Qt6-6.7.3-py3-none-win_amd64.whl (58.5 MB) Building wheels for collected packages: PyQt6-sip Building wheel for PyQt6-sip (pyproject.toml) ... error error: subprocess-exited-with-error × Building wheel for PyQt6-sip (pyproject.toml) did not run successfully. │ exit code: 1 ╰─> [5 lines of output] running bdist_wheel running build running build_ext building 'PyQt6.sip' extension error: Unable to find a compatible Visual Studio installation. [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. ERROR: Failed building wheel for PyQt6-sip Failed to build PyQt6-sip ERROR: ERROR: Failed to build installable wheels for some pyproject.toml based projects (PyQt6-sip)
解决方案
针对这个问题,我整理了几个可行的解决步骤,你可以依次尝试:
检查Visual Studio的工作负载和组件
Python 3.13要求使用Visual Studio 2022(版本17.x),并且必须安装「Desktop development with C++」工作负载。打开Visual Studio Installer,点击「修改」,确认勾选了以下关键组件:- MSVC v143 - VS 2022 C++ x64/x86生成工具
- Windows SDK(建议选择与你当前Windows系统版本匹配的SDK)
安装完成后重启电脑,再尝试重新安装PyQt6。
使用Visual Studio开发者命令提示符执行安装
即使安装了正确的组件,Python可能无法自动识别到编译环境。你可以打开「x64 Native Tools Command Prompt for VS 2022」(根据你的Python架构选择x64或x86),在这个命令窗口中运行pip install PyQt6——这个提示符会自动配置好编译所需的环境变量,帮助pip找到Visual Studio工具链。强制安装预编译的PyQt6-sip轮子
有时候pip会优先尝试从源码编译,你可以强制让pip使用预编译的二进制包,避免编译步骤。执行以下命令:pip install PyQt6-sip --only-binary :all:安装完成后再运行
pip install PyQt6,应该就能顺利完成了。确认Python与Visual Studio架构匹配
如果你使用的是64位Python,确保Visual Studio安装了64位的编译工具(一般「Desktop development with C++」默认会包含,但可以在Visual Studio Installer中确认)。如果是32位Python,则对应选择x86的工具集。
备注:内容来源于stack exchange,提问作者sheep8898




