Prepare a piece of python code
from __future__ import print_function def sum_nums(n): s=0 for i in range(n): s += i print(s) if __name__ == '__main__': sum_nums(5)
Then In the run and debug button on the left, click the "Create launch.json" file and select the python file (if not, you need to install the python extension first, and search for python in the application. The first one with the most installed ones can be used)
Select the python file
Generate the default launch file as follows
{ // 使用 IntelliSense 了解相关属性。 // 悬停以查看现有属性的描述。 // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "Python: 当前文件", "type": "python", "request": "launch", "program": "${file}", "console": "integratedTerminal", "justMyCode": true } ] }
Here we need to customize the python version used and add the "pythonPath" option
{ // 使用 IntelliSense 了解相关属性。 // 悬停以查看现有属性的描述。 // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "Python: 当前文件", "type": "python", "pythonPath": "/home/lthpc/anaconda3/bin/python3.7", "request": "launch", "program": "${file}", "console": "integratedTerminal", "justMyCode": true } ] }
In this case, you can use the specified python to run the code
If you use the conda virtual environment, you need to find the python path corresponding to the virtual environment. You can use whereis python to view
After configuring the debugging environment, put a breakpoint in the code, and then click the run debugging and execution button to enter the debugging page
The above is the detailed content of How to remotely debug python code with vscode. For more information, please follow other related articles on the PHP Chinese website!