How to remotely debug python code with vscode

WBOY
Release: 2023-04-30 21:13:05
forward
1270 people have browsed it

Environment configuration

Configure the python environment

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)
Copy after login

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
        }
    ]
}
Copy after login

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
        }
    ]
}
Copy after login

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

Debugging Code

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!