打开VSCode,安装Python Extension
3.1. Ctrl+P 调出控制台,敲ext install python
,点匹配出来的Python条目里面的云状图标下载,默默等待安装完成。 3.2. 新建一个文件夹,用VSCode打开该文件夹,并在其中新建一个test.py文件来做测试。
print("Hello VSCode")
a = 1
b = 2
c = a + b
print(c)
3.3. 在资源管理器中点test.py,敲F5,进入调试模式,在弹出的询问框中选择Python,此时在当前文件夹中会生成一个.vscode文件夹,其中有一个launch.json文件,记录了一些Debug的设置。敲F5后Debug会自动停留在程序开始处,再敲F5会运行完程序。
{
"version": "0.2.0",
"configurations": [
{
"name": "Python",
"type": "python",
"request": "launch",
"stopOnEntry": true,
"program": "${file}",
"debugOptions": [
"WaitOnAbnormalExit",
"WaitOnNormalExit",
"RedirectOutput"
]
},
{
"name": "Python Console App",
"type": "python",
"request": "launch",
"stopOnEntry": true,
"program": "${file}",
"externalConsole": true,
"debugOptions": [
"WaitOnAbnormalExit",
"WaitOnNormalExit"
]
},
{
"name": "Django",
"type": "python",
"request": "launch",
"stopOnEntry": true,
"program": "${workspaceRoot}/manage.py",
"args": [
"runserver",
"--noreload"
],
"debugOptions": [
"WaitOnAbnormalExit",
"WaitOnNormalExit",
"RedirectOutput",
"DjangoDebugging"
]
}
]
}
3.4. (Optional)配置Task,可以直接运行外部程序(这里是Python.exe,并不是完全懂)。在.vscode文件夹下新建task.json,敲ctrl+shift+B,可以直接运行test.py,相当于python test.py
{
"version":"0.1.0",
"command":"python",
"windows":{
"command":"python.exe"
},
"args":["test.py"]
}
原文地址http://www.bieryun.com/754.html