求助:安装webview库失败,无法构建wheel以安装pyproject.toml项目
解决Python安装webview库时的VC++编译错误问题
环境信息
- Python 3.11.0
- Windows 10 Pro Version 22H2(OS Build 19045.2728)
- 已安装Microsoft Visual C++ 2015-2022 Redistributable(x86/x64,版本14.32.31326)
- 已更新cmake、wheel、setuptools、pip
错误现象
执行pip install --use-pep517 webview时触发编译失败,提示缺少Microsoft Visual C++ 14.0+工具链,即使已安装C++ Build Tools仍无法解决,完整错误日志如下:
C:\Users\Bouregag Youcef>pip install --use-pep517 webview Collecting webview Using cached webview-0.1.5.tar.gz (18 kB) Installing build dependencies ... done Getting requirements to build wheel ... done Preparing metadata (pyproject.toml) ... done Building wheels for collected packages: webview Building wheel for webview (pyproject.toml) ... error error: subprocess-exited-with-error × Building wheel for webview (pyproject.toml) did not run successfully. │ exit code: 1 ╰─> [1 lines of output] 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 webview Failed to build webview ERROR: Could not build wheels for webview, which is required to install pyproject.toml-based projects
解决步骤
仅安装C++ Build Tools默认组件不包含编译Python扩展所需的完整工具链,需手动勾选特定组件:
- 打开Visual Studio Installer,在「已安装」标签找到「Microsoft Visual C++ Build Tools」,点击「修改」
- 在组件选择界面,确保勾选以下核心项:
- MSVC v143 - VS 2022 C++ x64/x86生成工具(根据系统架构选择,优先x64)
- Windows 10 SDK(选择与你的系统版本匹配的SDK版本,如10.0.19041.0及以上)
- C++ CMake工具for Windows
- 点击「修改」完成组件安装,安装结束后重启电脑
- 重新打开命令提示符/PowerShell,执行
pip install --use-pep517 webview重试安装
备选方案
若上述方法仍无效,可尝试安装预编译wheel包:
- 找到适配Python 3.11、Windows平台的webview预编译wheel文件
- 执行
pip install 本地wheel文件路径完成安装
内容的提问来源于stack exchange,提问作者Youcef Bouregag
相关产品推荐
相关产品推荐

