怎样安装pygame

2021年4月10日 | 分类: 【技术】

【介绍】

【安装:pip】

pip install pygame

执行命令后会下载文件:https://files.pythonhosted.org/packages/d2/ba/8e4f8fae51bd9d5766f1f20c9ce451e93929ee9efdd2784b1a7b469ea76e/pygame-1.9.6-cp38-cp38-win32.whl

【安装:手动下载 wheel 文件】

确认 python 版本:

本地Python版本:

C:\Users\amon>python

查看本地Python支持的安装包版本:

import pip._internal
print(pip._internal.pep425tags.get_supported())

下载 .whl 文件:

下载:https://pypi.org/project/pygame/#files
下载:http://www.pygame.org/download.shtml
下载:https://www.lfd.uci.edu/~gohlke/pythonlibs/

注意:
1. cp的意思是python的版本
2. 注意32位和64位

安装 .whl 文件:

C:\Users\amon>python -m pip install --user pygame-2.0.1-cp38-cp38-win32.whl
Processing c:\users\amon\pygame-2.0.1-cp38-cp38-win32.whl
Installing collected packages: pygame
Successfully installed pygame-2.0.1

【排错】

报错:.whl is not a supported wheel on this platform.

原因:
1. cp即python的版本不一致
2. 32位和64位错误

【测试】

1. 首先下载游戏文件并解压:http://122.51.113.73/alien_invasion.zip
2. 通过命令行进入解压文件目录,如d:\alien_invasion
3. 执行命令python alien_invasion.py即能打开游戏界面,如下图所示:

【参考】

参考:https://blog.csdn.net/cbb0201/article/details/103226941
参考:https://www.php.cn/python-tutorials-422577.html
参考:https://blog.csdn.net/yiminghd2861/article/details/83784087