Vscode debugging Python code

Introduction

  • Reference 0
  • Reference 1

1. Plugins

  • Official Python plugin
  • Code assistant, automatic completion:
  • Interpreter selection, select Interpreter in the bottom right corner of the window:

2. Environmental layout

  • Click debug:

  • Edit the launch.json file, first create the JSON file:

{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
  {
  	"python": "/home/CN/bo.feng/anaconda3/envs/nerf-pytorch/bin/python", //specify which one to use here python interpreter, if not specified, this setting defaults to the interpreter selected for your workspace, equivalent to using a value ${command:python.interpreterPath} 。
      "name": "Python: Current File",
      "type": "python",
      "request": "launch",
      "program": "/home/CN/bo.feng/NerfMap/nerf-pytoch/run_nerf.py", //this specification uses python run that file 
      "console": "integratedTerminal", //VS code integration terminal. if redirectOutput set to True the output will also be displayed in the debugging console. 
      "justMyCode": false, //when omitted or set to true when (default value) is set, debugging will be limited to user written code. set to false standard library function debugging can also be enabled. 
      "args": ["--config", "config/lego.txt"], //the parameters passed in by this specified model are those in the command line 
      "env": {"CUDA_VISIBLE_DEVICES":"0"} //this is a global environment variable, commonly used to specify which block GPU now 
  }
]
}

3. Parser parsing

parser.add_argument('–sampler_steps’, type=int, nargs='*’, default=[50, 90, 120]) 
  • Use to separate "- sampler_steps", "50", "90", "120",
  • Whether it is a string type or an int type, it is placed in" "Just use it, such as' 3 'and' str ', don't use it."' Str '"
  • Need to press F5 or Ctrl+ F5 enters debug, cannot click on the built-in debug in the upper right corner of vscode, otherwise it will be invalid.

Related articles