Official debugging manual: vscode official debugging manual
1. Install python extension
If you are connecting remotely, be sure to enable extensions on ssh. Otherwise, when creating a python-based configuration file, you will be prompted that there is no python extension.
2. Create a new configuration file and modify parameters
Click the fourth button on the left to run and debug
Click to create a configuration file (create a launch .json)
Select python file
This file is located in your folder.
The generated configuration file looks like this:
The name of the name project can be chosen by yourself.
type is the running file type.
program is the running file address.
args are input parameters.
Save the configuration after modification is completed
3. Modify the compiler
Modify the environment compiler in the lower right corner.
Select the compiler in the conda environment or the local compiler required to run the file.
4. Add breakpoints
Add breakpoint
Select breakpoint
5. Debugging
Click the green triangle to debug.
In addition, when debugging, it is shown that files in the same directory cannot be called. The following code needs to be added to the running file.
import sys
sys.path.append("/root/XXX") # 该路径为运行文件所在的项目文件夹