在Windows 10通过CMD与pip安装pygame时遇错误求助
问题
Windows 10 Pro系统下,执行py -3.10 -m pip install pygame或pip install pygame均触发以下错误:
Microsoft Windows [Version 10.0.19044.2251] (c) Microsoft Corporation. All rights reserved. C:\Users\User>py -3.10 -m pip install pygame Collecting pygame Using cached pygame-2.1.2.tar.gz (10.1 MB) Preparing metadata (setup.py) ... error error: subprocess-exited-with-error × python setup.py egg_info did not run successfully. │ exit code: 1 ╰─> [77 lines of output] WARNING, No "Setup" File Exists, Running "buildconfig/config.py" Using WINDOWS configuration... # 完整错误核心:缺少Microsoft Visual C++ 14.0及以上版本的构建环境 [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. error: metadata-generation-failed × Encountered error while generating package metadata. ╰─> See above for output. note: This is an issue with the package mentioned above, not pip. hint: See above for details.
解决方法
- 直接安装预编译包(推荐)
执行命令跳过本地编译,直接使用官方预编译的二进制包:py -3.10 -m pip install pygame --only-binary :all: - 安装C++构建环境(若需本地编译)
- 下载微软Visual Studio构建工具,安装时勾选「C++构建工具」组件(包含MSVC编译器、Windows SDK等必要文件)。
- 安装完成后重启命令提示符,再重新执行
py -3.10 -m pip install pygame。
- 更新pip版本
先升级pip到最新版,修复可能的兼容性问题:py -3.10 -m pip install --upgrade pip
内容的提问来源于stack exchange,提问作者Ethan Paylor
相关产品推荐
相关产品推荐

