下载安装 Python
官网地址:https://www.python.org
- 在安装过程中,务必勾选 “Add Python x.x to PATH” 选项,这样可以在命令行中直接运行 Python。
- 完成安装后,按下 Win+R 键,输入 “cmd” 打开命令提示符,输入
python -v
来验证安装是否成功,如果看到版本号显示,则表示 Python 已成功安装。
安装 VS Code Python 扩展
搜索并安装 Python 扩展。
运行 Python 代码
python filename.py
注意一定要带
python
,Linux 环境下可能是python3
在 VS Code 环境中,按下快捷键 Ctrl + F5
运行程序。
注:第一次按下
Ctrl + F5
会提示选择编译器,此时选择Python Debugger..
更换 PIP 源
pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/
更新 PIP
python -m pip install --upgrade pip
安装 pytest
python -m pip install --user pytest
运行 pytest
在 Terminal 中输入 pytest
如果在执行命令 pytest
时没有制定任何参数,pytest 将运行它在当前目录中找到的所有测试。要测试指定文件,使用 pytest test_filename.py
安装 pygame
python -m pip install --user pygame
在pygame 界面中,如果要检测按键,需确保输入法为英文,否则即使程序正确也会出现按键无效的现象。