打开新项目左边的“运行和调试”
点击蓝色字体“创建 launch.json 文件”
选择上方“python”
选择“Python 文件 调试当前正在运行的Python文件”
配置launch.json文件内容:

{
   // 使用 IntelliSense 了解相关属性
   // 悬停以查看现有属性的描述。
   // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
   "version": "0.2.0",
   "configurations": [                
       {
           "name": "Python: Current File",
           "type": "python",
           "request": "launch",
           "program": "${file}",
           "console": "integratedTerminal",
           "justMyCode": true,
           "env": {"PYDEVD_WARN_SLOW_RESOLVE_TIMEOUT": "2"},
           "cwd": "${fileDirname}",
           "args": ["./configs/xxx.yaml",
           			"--a", "A",
           			"--b", "B"
           ]         
       }
   ]
}

"name": "Python: Current File", 自定义的debug名字Python: Current File。可以通过增加多个{}块定义多个debug环境。
"program": "${file}", 项目debug入口位置。 “${file}“表示当前文件;”${workspaceFolder}/train.py"表示项目的train.py文件。
"justMyCode": true debug的文件。ture表示只有当前项目文件,而没有import的包文件。
"env": {"PYDEVD_WARN_SLOW_RESOLVE_TIMEOUT": "2"} 多长时间显示 pydevd warnings
"cwd": "${fileDirname}" debug时的当前路径。”${fileDirname}"表示当前debug文件路径; "${workspaceFolder}"表示当前项目根目录。
"args": ["xxx", "xxx"] debug时传入的参数

Logo

汇聚全球AI编程工具,助力开发者即刻编程。

更多推荐