如何在vscode launch.json中调试python模块

2024-05-29 03:36:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我的问题似乎很简单,但我有一个模块,我在这样的终端上启动: bash python -m my_module.my_file

如何在Visual Studio代码中调试它。

我的launch.jsondocumentation)里有这个

"type": "python",
"request": "launch",
"pythonPath": "D:\\ProgramData\\Anaconda3\\envs\\simulec\\python.exe",
"args": [
   "-m",
   "my_module.my_file",
]

如果我没有设置program选项,或者将其设置为"",则会出现“文件不存在”错误。

知道吗? 提前谢谢


Tags: 模块代码bashjson终端requestmydocumentation
2条回答
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "module",
            "type": "pythonExperimental",
            "request": "launch",
            "module": "my_package.my_module.${fileBasenameNoExtension}",
        },
    ]
}

实际上,我在尝试编辑launch.json时偶然发现了一个非常简单的选项。

"type": "python",
"request": "launch",
"pythonPath": "D:\\ProgramData\\Anaconda3\\envs\\simulec\\python.exe",
"module": "my_module.my_file",

只需在模块键中指定模块"module": "my_module.my_file"

-m不再有用

相关问题 更多 >

    热门问题