关于Pygame安装失败问题
安装Pygame失败,报错。已经重新卸载、安装一次Python,仍然报错。报错信息的图片在附件。
请大家帮我看看是什么原因导致的,怎么解决,谢谢回复的朋友。
用Pycharm安装也出错
Pycharm错误日志:
C:\Users\lvhanyu\PyCharmMiscProject\.venv\Scripts\python.exe D:/JetBrains/PyCharm 2025.2.3/plugins/python-ce/helpers/packaging_tool.py install pygame
Collecting pygame
Using cached pygame-2.6.1.tar.gz (14.8 MB)
Installing build dependencies: started
Installing build dependencies: finished with status 'done'
Getting requirements to build wheel: started
Getting requirements to build wheel: still running...
Getting requirements to build wheel: finished with status 'error'
Could not find platform independent libraries <prefix>
error: subprocess-exited-with-error
Getting requirements to build wheel did not run successfully.
exit code: 1
Could not find platform independent libraries <prefix>
Skipping Cython compilation
WARNING, No "Setup" File Exists, Running "buildconfig/config.py"
Using WINDOWS configuration...
Making dir :prebuilt_downloads:
Downloading... https://www.libsdl.org/release/SDL2-devel-2.28.4-VC.zip 25ef9d201ce3fd5f976c37dddedac36bd173975c
Unzipping :prebuilt_downloads\SDL2-devel-2.28.4-VC.zip:
Downloading... https://www.libsdl.org/projects/SDL_image/release/SDL2_image-devel-2.0.5-VC.zip 137f86474691f4e12e76e07d58d5920c8d844d5b
Unzipping :prebuilt_downloads\SDL2_image-devel-2.0.5-VC.zip:
Downloading... https://github.com/libsdl-org/SDL_ttf/releases/download/release-2.20.1/SDL2_ttf-devel-2.20.1-VC.zip 371606aceba450384428fd2852f73d2f6290b136
Unzipping :prebuilt_downloads\SDL2_ttf-devel-2.20.1-VC.zip:
Downloading... https://github.com/libsdl-org/SDL_mixer/releases/download/release-2.6.2/SDL2_mixer-devel-2.6.2-VC.zip 000e3ea8a50261d46dbd200fb450b93c59ed4482
Unzipping :prebuilt_downloads\SDL2_mixer-devel-2.6.2-VC.zip:
Downloading... https://github.com/pygame/pygame/releases/download/2.1.3.dev4/prebuilt-x64-pygame-2.1.4-20220319.zip 16b46596744ce9ef80e7e40fa72ddbafef1cf586
Unzipping :prebuilt_downloads\prebuilt-x64-pygame-2.1.4-20220319.zip:
copying into .\prebuilt-x64
Path for SDL: prebuilt-x64\SDL2-2.28.4
...Library directory for SDL: prebuilt-x64/SDL2-2.28.4/lib/x64
...Include directory for SDL: prebuilt-x64/SDL2-2.28.4/include
Path for FONT: prebuilt-x64\SDL2_ttf-2.20.1
...Library directory for FONT: prebuilt-x64/SDL2_ttf-2.20.1/lib/x64
...Include directory for FONT: prebuilt-x64/SDL2_ttf-2.20.1/include
Path for IMAGE: prebuilt-x64\SDL2_image-2.0.5
...Library directory for IMAGE: prebuilt-x64/SDL2_image-2.0.5/lib/x64
...Include directory for IMAGE: prebuilt-x64/SDL2_image-2.0.5/include
Path for MIXER: prebuilt-x64\SDL2_mixer-2.6.2
...Library directory for MIXER: prebuilt-x64/SDL2_mixer-2.6.2/lib/x64
...Include directory for MIXER: prebuilt-x64/SDL2_mixer-2.6.2/include
Path for PORTMIDI: prebuilt-x64
...Library directory for PORTMIDI: prebuilt-x64/lib
...Include directory for PORTMIDI: prebuilt-x64/include
DLL for SDL2: prebuilt-x64/SDL2-2.28.4/lib/x64/SDL2.dll
DLL for SDL2_ttf: prebuilt-x64/SDL2_ttf-2.20.1/lib/x64/SDL2_ttf.dll
DLL for SDL2_image: prebuilt-x64/SDL2_image-2.0.5/lib/x64/SDL2_image.dll
DLL for SDL2_mixer: prebuilt-x64/SDL2_mixer-2.6.2/lib/x64/SDL2_mixer.dll
DLL for portmidi: prebuilt-x64/lib/portmidi.dll
Path for FREETYPE: prebuilt-x64
...Library directory for FREETYPE: prebuilt-x64/lib
...Include directory for FREETYPE: prebuilt-x64/include
Path for PNG not found.
...Found include dir but no library dir in prebuilt-x64.
Path for JPEG not found.
...Found include dir but no library dir in prebuilt-x64.
DLL for freetype: prebuilt-x64/lib/freetype.dll
DLL for png: prebuilt-x64/SDL2_image-2.0.5/lib/x64/libpng16-16.dll
---
For help with compilation see:
https://www.pygame.org/wiki/CompileWindows
To contribute to pygame development see:
https://www.pygame.org/contribute.html
---
Traceback (most recent call last):
File "C:\Users\lvhanyu\AppData\Local\Temp\pip-install-yc91kluf\pygame_2ea6daf0dc9e458abe96034240c0c800\buildconfig\vstools.py", line 4, in <module>
from distutils.msvccompiler import MSVCCompiler, get_build_architecture
ModuleNotFoundError: No module named 'distutils.msvccompiler'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\lvhanyu\AppData\Local\Temp\pip-install-yc91kluf\pygame_2ea6daf0dc9e458abe96034240c0c800\buildconfig\config_win.py", line 336, in configure
from . import vstools
File "C:\Users\lvhanyu\AppData\Local\Temp\pip-install-yc91kluf\pygame_2ea6daf0dc9e458abe96034240c0c800\buildconfig\vstools.py", line 6, in <module>
from setuptools._distutils.msvccompiler import MSVCCompiler, get_build_architecture
ModuleNotFoundError: No module named 'setuptools._distutils.msvccompiler'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\lvhanyu\AppData\Local\Temp\pip-install-yc91kluf\pygame_2ea6daf0dc9e458abe96034240c0c800\buildconfig\vstools.py", line 4, in <module>
from distutils.msvccompiler import MSVCCompiler, get_build_architecture
ModuleNotFoundError: No module named 'distutils.msvccompiler'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\lvhanyu\PyCharmMiscProject\.venv\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 389, in <module>
main()
~~~~^^
File "C:\Users\lvhanyu\PyCharmMiscProject\.venv\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 373, in main
json_out["return_val"] = hook(**hook_input["kwargs"])
~~~~^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\lvhanyu\PyCharmMiscProject\.venv\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 143, in get_requires_for_build_wheel
return hook(config_settings)
File "C:\Users\lvhanyu\AppData\Local\Temp\pip-build-env-xswo2ctn\overlay\Lib\site-packages\setuptools\build_meta.py", line 331, in get_requires_for_build_wheel
return self._get_build_requires(config_settings, requirements=[])
~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\lvhanyu\AppData\Local\Temp\pip-build-env-xswo2ctn\overlay\Lib\site-packages\setuptools\build_meta.py", line 301, in _get_build_requires
self.run_setup()
~~~~~~~~~~~~~~^^
File "C:\Users\lvhanyu\AppData\Local\Temp\pip-build-env-xswo2ctn\overlay\Lib\site-packages\setuptools\build_meta.py", line 512, in run_setup
super().run_setup(setup_script=setup_script)
~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\lvhanyu\AppData\Local\Temp\pip-build-env-xswo2ctn\overlay\Lib\site-packages\setuptools\build_meta.py", line 317, in run_setup
exec(code, locals())
~~~~^^^^^^^^^^^^^^^^
File "<string>", line 432, in <module>
File "C:\Users\lvhanyu\AppData\Local\Temp\pip-install-yc91kluf\pygame_2ea6daf0dc9e458abe96034240c0c800\buildconfig\config.py", line 234, in main
deps = CFG.main(**kwds, auto_config=auto)
File "C:\Users\lvhanyu\AppData\Local\Temp\pip-install-yc91kluf\pygame_2ea6daf0dc9e458abe96034240c0c800\buildconfig\config_win.py", line 493, in main
return setup_prebuilt_sdl2(prebuilt_dir)
File "C:\Users\lvhanyu\AppData\Local\Temp\pip-install-yc91kluf\pygame_2ea6daf0dc9e458abe96034240c0c800\buildconfig\config_win.py", line 453, in setup_prebuilt_sdl2
DEPS.configure()
~~~~~~~~~~~~~~^^
File "C:\Users\lvhanyu\AppData\Local\Temp\pip-install-yc91kluf\pygame_2ea6daf0dc9e458abe96034240c0c800\buildconfig\config_win.py", line 338, in configure
from buildconfig import vstools
File "C:\Users\lvhanyu\AppData\Local\Temp\pip-install-yc91kluf\pygame_2ea6daf0dc9e458abe96034240c0c800\buildconfig\vstools.py", line 6, in <module>
from setuptools._distutils.msvccompiler import MSVCCompiler, get_build_architecture
ModuleNotFoundError: No module named 'setuptools._distutils.msvccompiler'
note: This error originates from a subprocess, and is likely not a problem with pip.
A new release of pip is available: 25.1.1 -> 25.2
To update, run: python.exe -m pip install --upgrade pip
error: subprocess-exited-with-error
Getting requirements to build wheel did not run successfully.
exit code: 1
See above for output.
note: This error originates from a subprocess, and is likely not a problem with pip.
Process finished with exit code 1 根据错误信息,问题主要出现在缺少 distutils.msvccompiler 模块上。这是Windows系统安装Pygame时常见的编译依赖问题。
解决方案:
[*]安装Microsoft Visual C++ Build Tools
前往微软官网下载并安装 Build Tools for Visual Studio 2022,安装时务必勾选“C++ 生成工具”工作负载
[*]安装必要的Python构建工具
在命令提示符中执行:
pip install setuptools wheel
pip install --upgrade setuptools
[*]尝试使用预编译的Pygame包
直接安装预编译的whl文件,避免源码编译:
pip install pygame --prefer-binary
[*]或者指定使用较旧但更稳定的版本:
pip install pygame==2.5.2
[*]如果上述方法仍不行,尝试使用conda安装:
conda install -c conda-forge pygame
重要提示:
- 确保Python版本与系统架构匹配(32位/64位)
- 安装时关闭所有杀毒软件,避免干扰编译过程
- 如果使用PyCharm,可以尝试在终端中直接运行pip命令而不是通过IDE的包管理器
建议按顺序尝试以上方法,通常安装VC++ Build Tools就能解决问题。
以上回复来自 FishC AI 小助理,如未能正确解答您的问题,请继续追问。 FishC 发表于 2025-10-25 17:30
根据错误信息,问题主要出现在缺少 distutils.msvccompiler 模块上。这是Windows系统安装Pygame时常见的编 ...
怎么确认自己有没有安装VC++ Build Tools ChinoLv 发表于 2025-10-25 18:35
FishC 发表于 2025-10-25 17:30
根据错误信息,问题 ...
你可以通过以下几种方式检查是否安装了VC++ Build Tools:
方法一:通过控制面板检查
[*] 按 Win + R 键打开运行对话框
[*] 输入 appwiz.cpl 并回车
[*] 在已安装程序列表中查找以下名称:
[*] Microsoft Visual C++ Build Tools
[*] Build Tools for Visual Studio 2022
[*] Visual Studio Build Tools(任何年份版本)
方法二:通过PowerShell检查
[*] 按 Win + X 键,选择“Windows PowerShell”或“终端”
[*] 输入以下命令并回车:
Get-WmiObject -Class Win32_Product | Where-Object {$_.Name -like "*Build Tools*"}
[*] 如果返回结果,则表示已安装
方法三:通过Visual Studio Installer检查
[*] 如果已安装Visual Studio,打开“Visual Studio Installer”
[*] 点击“修改”按钮
[*] 查看已安装的工作负载中是否包含“C++ 生成工具”
如果以上方法均未找到,说明没有安装VC++ Build Tools。建议前往微软官网下载并安装“Build Tools for Visual Studio 2022”,安装时务必勾选“C++ 生成工具”工作负载。
以上回复来自 FishC AI 小助理,如未能正确解答您的问题,请继续追问。
页:
[1]