Python 3.10 不支持 pygame 吗?

Doesn't Python 3.10 support pygame?

我刚刚安装了测试版 Python 3.10,打开 VS Code,将 Python Interpreter 更改为 Python 3.10 64 位(我的 PC 使用 64 位)并设法继续我的 Pygame 项目。

然而,当我运行代码时,我遇到了 ModuleNotFoundError 提示:没有名为 Pygame 的模块。 (虽然 pygame 模块已完美安装)

那是因为 Python 的测试版吗?如果是的话,难道没有一些方法可以同时使用 pygame 和 python3.10 吗?

我认为这可能是兼容性问题。

pip3.9 install pygame

工作正常。

pip3.10 install pygame

returns 大量 个错误。其中一些是 pip/pygame 与轮子和依赖项有关的错误。所以我在本地克隆了 pygame 源存储库并尝试从源代码构建它。

python3.9 setup.py build;
python3.9 setup.py install

按预期工作。

python3.10 setup.py build;
python3.10 setup.py install

达到 20 个错误的关键限制并决定完成。我已经尝试了多种适用于 pygame 和 python 旧版本的解决方法和解决方案,但不幸的是没有任何效果,所以我认为这真的只是一个兼容性问题,我们必须等待 pygame 更新以使用 python 3.10.

如果 pip install pygame 和 python 3.10 产生错误,您可以随时通过使用来自该网站的 .whl 文件安装来重试: https://www.lfd.uci.edu/~gohlke/pythonlibs/#pygame

安装可能如下所示:

pip install {path-to-whl-file}/pygame-2.0.1-cp310-cp310-win_amd64.whl

对于 MAC 用户

Python 3.10 安装程序是通用的,这意味着它 运行 默认是 Python 3.10 的 ARM64 版本。由于 Pygame 尚未在 ARM64 上更新为 运行,您需要在 Rosetta 中将 运行 Python 3.10 更新为 Shell 使用命令:python3-intel64

import pygame 将与 Python 3.10

一起正常工作

要在 VS Code 中使用它,您需要将 settings.json 文件更改为:

"python.defaultInterpreterPath" : "/usr/local/bin/python3-intel64"

然后select编辑的翻译。