鱼C论坛

 找回密码
 立即注册
查看: 23|回复: 1

如何安装pygame

[复制链接]
发表于 6 小时前 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
请问Python3.14.3 有匹配的 Pagame版本吗?

pip install pygame未能成功,提示如下,求指点

PS C:\Users\SUN366\MyPython\Tools> pip install pygame
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting pygame
  Downloading https://pypi.tuna.tsinghua.edu.c ... pygame-2.6.1.tar.gz (14.8 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 14.8/14.8 MB 40.7 MB/s  0:00:00
  Installing build dependencies ... done
  Getting requirements to build wheel ... error
  error: subprocess-exited-with-error

  × Getting requirements to build wheel did not run successfully.
  │ exit code: 1
  ╰─> [112 lines of output]
      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/ ... -devel-2.0.5-VC.zip 137f86474691f4e12e76e07d58d5920c8d844d5b
      Unzipping :prebuilt_downloads\SDL2_image-devel-2.0.5-VC.zip:
      Downloading... https://github.com/libsdl-org/SD ... devel-2.20.1-VC.zip 371606aceba450384428fd2852f73d2f6290b136
      Unzipping :prebuilt_downloads\SDL2_ttf-devel-2.20.1-VC.zip:
      Downloading... https://github.com/libsdl-org/SD ... -devel-2.6.2-VC.zip 000e3ea8a50261d46dbd200fb450b93c59ed4482
      Unzipping :prebuilt_downloads\SDL2_mixer-devel-2.6.2-VC.zip:
      Downloading... https://github.com/pygame/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\SUN366\AppData\Local\Temp\pip-install-bkesyc_5\pygame_d9276307516d4c578562653588eb555e\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\SUN366\AppData\Local\Temp\pip-install-bkesyc_5\pygame_d9276307516d4c578562653588eb555e\buildconfig\config_win.py", line 336, in configure
          from . import vstools
        File "C:\Users\SUN366\AppData\Local\Temp\pip-install-bkesyc_5\pygame_d9276307516d4c578562653588eb555e\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\SUN366\AppData\Local\Temp\pip-install-bkesyc_5\pygame_d9276307516d4c578562653588eb555e\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\SUN366\AppData\Local\Programs\Python\Python314\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 389, in <module>
          main()
          ~~~~^^
        File "C:\Users\SUN366\AppData\Local\Programs\Python\Python314\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\SUN366\AppData\Local\Programs\Python\Python314\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\SUN366\AppData\Local\Temp\pip-build-env-r4bhs6r2\overlay\Lib\site-packages\setuptools\build_meta.py", line 333, in get_requires_for_build_wheel
          return self._get_build_requires(config_settings, requirements=[])
                 ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "C:\Users\SUN366\AppData\Local\Temp\pip-build-env-r4bhs6r2\overlay\Lib\site-packages\setuptools\build_meta.py", line 301, in _get_build_requires
          self.run_setup()
          ~~~~~~~~~~~~~~^^
        File "C:\Users\SUN366\AppData\Local\Temp\pip-build-env-r4bhs6r2\overlay\Lib\site-packages\setuptools\build_meta.py", line 520, in run_setup
          super().run_setup(setup_script=setup_script)
          ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "C:\Users\SUN366\AppData\Local\Temp\pip-build-env-r4bhs6r2\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\SUN366\AppData\Local\Temp\pip-install-bkesyc_5\pygame_d9276307516d4c578562653588eb555e\buildconfig\config.py", line 234, in main
          deps = CFG.main(**kwds, auto_config=auto)
        File "C:\Users\SUN366\AppData\Local\Temp\pip-install-bkesyc_5\pygame_d9276307516d4c578562653588eb555e\buildconfig\config_win.py", line 493, in main
          return setup_prebuilt_sdl2(prebuilt_dir)
        File "C:\Users\SUN366\AppData\Local\Temp\pip-install-bkesyc_5\pygame_d9276307516d4c578562653588eb555e\buildconfig\config_win.py", line 453, in setup_prebuilt_sdl2
          DEPS.configure()
          ~~~~~~~~~~~~~~^^
        File "C:\Users\SUN366\AppData\Local\Temp\pip-install-bkesyc_5\pygame_d9276307516d4c578562653588eb555e\buildconfig\config_win.py", line 338, in configure
          from buildconfig import vstools
        File "C:\Users\SUN366\AppData\Local\Temp\pip-install-bkesyc_5\pygame_d9276307516d4c578562653588eb555e\buildconfig\vstools.py", line 6, in <module>
          from setuptools._distutils.msvccompiler import MSVCCompiler, get_build_architecture
      ModuleNotFoundError: No module named 'setuptools._distutils.msvccompiler'
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed to build 'pygame' when getting requirements to build wheel
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 6 小时前 | 显示全部楼层
鱼油你好,安装Pygame遇到问题通常是由于Python版本兼容性或缺少编译工具引起的。根据你提供的错误信息,问题主要出在distutils.msvccompiler模块缺失,这在较新的Python版本中常见。

Python 3.14.3 有匹配的 Pagame版本吗?


1. 关于Python版本
目前,Pygame官方尚未支持Python 3.14(错误提示显示为Python314)。建议使用Python 3.12或3.11这些稳定版本,它们有预编译的Pygame安装包,安装更简单。

你可以通过以下命令查看当前Python版本:

  1. python --version
复制代码


2. 解决方案
请按照以下步骤尝试:

步骤一:更新pip和setuptools
打开命令提示符(以管理员身份运行),执行:

  1. python -m pip install --upgrade pip setuptools
复制代码


步骤二:安装Microsoft C++ Build Tools
由于Pygame需要编译C扩展,你必须安装Visual Studio Build Tools。
- 访问微软官网,下载“Microsoft C++ Build Tools”
- 运行安装程序,选择“使用C++的桌面开发”工作负载
- 安装完成后重启电脑

步骤三:尝试安装Pygame
如果使用Python 3.12或更早版本,可以直接安装:

  1. pip install pygame
复制代码


如果仍失败,可以尝试:

  1. pip install pygame==2.6.0
复制代码


步骤四:使用虚拟环境(推荐)
如果上述方法无效,建议创建Python 3.12的虚拟环境:

  1. # 创建虚拟环境
  2. python -m venv pygame_env

  3. # 激活虚拟环境(Windows)
  4. pygame_env\Scripts\activate

  5. # 安装Pygame
  6. pip install pygame
复制代码


3. 快速解决方案
最直接的方法是:
1. 卸载当前Python 3.14
2. 从Python官网下载并安装Python 3.12.3
3. 安装时务必勾选“Add Python to PATH”
4. 重新打开命令提示符,执行:pip install pygame

这样通常可以一次性成功安装Pygame。

如果还有其他问题,请随时提问!

以上回复来自 FishC AI 小助理,如未能正确解答您的问题,请继续追问。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2026-2-7 18:20

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表