成功解决python报错:Building wheel for PyQt5-sip (pyproject.toml) did not run successfully。error: Microsoft Visual C++ 14.0 or greater is required. Get it with “Microsoft C++ Build Tools”: https://visualstudio.microsoft.com/visual-cpp-build-tools/
🧑 博主简介:现任阿里巴巴嵌入式技术专家,15年工作经验,深耕嵌入式+人工智能领域,精通嵌入式领域开发、技术管理、简历招聘面试。CSDN优质创作者,提供产品测评、学习辅导、简历面试辅导、毕设辅导、项目开发、C/C++/Java/Python/Linux/AI等方面的服务,如有需要请站内私信或者联系任意文章底部的的VX名片(ID:
gylzbk
)
💬 博主粉丝群介绍:① 群内高中生、本科生、研究生、博士生遍布,可互相学习,交流困惑。② 热榜top10的常客也在群里,也有数不清的万粉大佬,可以交流写作技巧,上榜经验,涨粉秘籍。③ 群内也有职场精英,大厂大佬,可交流技术、面试、找工作的经验。④ 进群免费赠送写作秘籍一份,助你由写作小白晋升为创作大佬。⑤ 进群赠送CSDN评论防封脚本,送真活跃粉丝,助你提升文章热度。有兴趣的加文末联系方式,备注自己的CSDN昵称,拉你进群,互相学习共同进步。
【Python】解决pip报错:Building wheel for PyQt5-sip (pyproject.toml) did not run successfully
问题背景
Windows平台安装PyQt的过程中,会遇到error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
的报错导致安装失败。本文将带你一步一步通过2种方法解决这个问题。
问题现象
使用pip来安装PyQt5和相关工具包:
pip install PyQt5 PyQt5-tools
安装过程中有如下错误:
Using cached colorama-0.4.6-py2.py3-none-any.whl (25 kB)
Using cached importlib_metadata-6.7.0-py3-none-any.whl (22 kB)
Using cached qt5_applications-5.15.2.2.3-py3-none-win_amd64.whl (64.5 MB)
Using cached typing_extensions-4.7.1-py3-none-any.whl (33 kB)
Using cached zipp-3.15.0-py3-none-any.whl (6.8 kB)
Building wheels for collected packages: PyQt5-sip
Building wheel for PyQt5-sip (pyproject.toml): started
Building wheel for PyQt5-sip (pyproject.toml): finished with status 'error'
error: subprocess-exited-with-error
Building wheel for PyQt5-sip (pyproject.toml) did not run successfully.
exit code: 1
[5 lines of output]
running bdist_wheel
running build
running build_ext
building 'PyQt5.sip' extension
error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for PyQt5-sip
Failed to build PyQt5-sip
ERROR: Could not build wheels for PyQt5-sip, which is required to install pyproject.toml-based projects
解决方案1:安装Microsoft C++ Build Tools
Windows平台安装过程中遇到这个错误,说明需要用到Microsoft C++ Build Tools
。大概步骤如下:
1. 下载Microsoft C++ Build Tools
- 访问微软开发工具官方下载网站:https://visualstudio.microsoft.com/visual-cpp-build-tools/
- 点击下载生成工具按钮,下载安装包。安装包只是个壳,很快就可以下载完成。
2. 安装Microsoft C++ Build Tools
运行安装包,如下图所示,点击继续
按钮,进入安装界面之后,选择使用C++的桌面开发
,然后点击右下角的安装,直至安装完成即可。
3. 重新安装PyQt
重新执行pyqt安装命令,即可安装成功。
pip install PyQt5 PyQt5-tools
解决方案2:手动下载安装whl文件
下载安装Microsoft C++ Build Tools
,需要很长的时间,另外需要下载大量的文件,耗时费力。如果你不想那么费事,还可以手动下载whl文件,手动安装,以跳过这个错误。
方法如下:
1. 下载whl文件
whl下载地址:https://pypi.tuna.tsinghua.edu.cn/simple/pyqt5-sip/。比如我是Win10 64位(对应win_amd64)
系统,python版本为3.7.0(对应cp37)
,所以我选择了适配与我的系统和python版本的PyQt5_sip最新版本whl文件:PyQt5_sip-12.12.2-cp37-cp37m-win_amd64.whl。
2. 安装whl
whl文件下载后使用pip install PyQt5_sip-12.12.2-cp37-cp37m-win_amd64.whl
命令安装它。
3. 重新安装PyQt
最后,重新执行pyqt安装命令,如下图所示,即可安装成功。
pip install PyQt5 PyQt5-tools