安装discord.py时提示需VS Build Tools,已安装仍报错求助
报错信息:
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 multidict
Failed to build multidict
ERROR: Could not build wheels for multidict, which is required to install pyproject.toml-based projects
具体解决步骤:
确认VS Build Tools组件完整性
打开VS Installer,找到已安装的「Visual Studio Build Tools」点击「修改」,必须勾选**「桌面开发用C++」工作负载**,并确保子组件包含:- MSVC v142及以上版本生成工具
- 匹配你系统版本的Windows 10/11 SDK
- C++ CMake工具
安装完成后务必重启电脑,确保环境变量生效。
跳过编译,直接安装预编译multidict包
执行命令强制安装预编译的wheel版本,避免源码编译:pip install multidict --only-binary :all:完成后再安装discord.py:
pip install discord.py检查Python与工具集架构匹配
确保Python的32/64位架构和VS Build Tools安装的工具集一致。执行以下命令查看Python架构:python -c "import sys; print('64位' if sys.maxsize > 2**32 else '32位')"若为64位Python,VS Build Tools需勾选对应x64的工具集选项。
升级pip及相关依赖工具
旧版本pip可能不兼容新wheel格式,执行升级命令:python -m pip install --upgrade pip setuptools wheel国内镜像源加速(可选)
若网络问题导致预编译包下载失败,切换国内PyPI镜像源安装:pip install multidict --only-binary :all: -i https://pypi.tuna.tsinghua.edu.cn/simple
内容的提问来源于stack exchange,提问作者Layla Elateek

