【VSCode中Python的Debug调试配置】

  • VScode 会在每个项目文件夹下创建一个.vscode文件夹,保存当前项目的运行环境的配置文件。
    在这里插入图片描述

  • launch.json

  • tasks.json

  • settings.json

在这里插入图片描述

如果 Debug 调试 没有反应,可以自行创建添加这三个文件,修改其中的 Python 环境的解释器路径地址,进行解决

  • launch.json
# launch.json
{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    // "version": "0.2.0",
    // "configurations": [
    //     {
    //         "name": "Python: 当前文件",
    //         "type": "python",
    //         "request": "launch",
    //         "program": "${file}",
    //         "console": "integratedTerminal"
     "version": "0.2.0",
    "configurations": [
        
        {
            "name": "Python",
            "type": "python",
            "request": "launch",
            "stopOnEntry": false,
            "python": "D:\\Anaconda\\python.exe", # 自己的Python环境解释器地址
            "program": "${file}",
            "cwd": "${workspaceRoot}",
            "env": {},
            "envFile": "${workspaceRoot}/.env",
            "redirectOutput": true,

        }
    ]
}

  • 不同的虚拟环境,Python解释器的路径不同:
    在这里插入图片描述

  • tasks.json

# tasks.json
{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "python",
            "type": "shell",
            "command": "D:\\Anaconda\\python.exe",
            "args": [
                "${file}"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "problemMatcher": [
                "$eslint-compact"
            ]
        }
    ]
}

  • tasks.json
# tasks.json
{
    "python.pythonPath": "D:\\Anaconda\\python.exe"
}

  • Debug 单步调试

在这里插入图片描述

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐