如何在VSCode中调试Python?

huangapple go评论68阅读模式
英文:

How to debug python in vscode?

问题

我有点困惑。如果 VSCode 不在与此脚本相同的文件夹中,我无法启动 Python 调试。但我可以使用“运行 Python 文件”启动它。

如果我将以下文本添加到 launch.json 中:

{
    "name": "Python: Debug script",
    "type": "python",
    "request": "launch",
    "program": "${file}",
    "cwd": "${fileDirname}"
}

然后我可以使用“运行和调试”按钮启动调试。如何使“调试 Python 文件”按钮工作?

英文:

Im little confused. I can not start debug python if vscode is not located on same folder with this script. But i can start it with "Run python file".

If i add to launch.json this text:

   {
 "name": "Python: Debug script",
 "type": "python",
 "request": "launch",
 "program": "${file}",
 "cwd": "${fileDirname}"
    }

then i can start debug it with Run And Debug button. How to make it works the "Debug python file" button?

答案1

得分: 2

请注意,按钮中的Debug Python File选项不使用launch.json中的配置。如果您需要使用launch.json配置来调试脚本,您需要点击Run and Debug面板上的绿色三角形按钮,或者在Run菜单下使用Start DebuggingRun Without Debugging选项。

如果您想要调试特定脚本并配置*program*选项。

至于右上角的播放按钮是否可以配置,您可以查看几个现有的GitHub链接。

允许配置“在终端中运行Python文件”按钮

VS Code和Python:配置编辑器标签旁边的“运行”按钮

从运行按钮下拉菜单中列出运行配置

英文:

It should be noted that the Debug Python File options in the button do not use the configuration in launch.json. If you need to use the launch.json configuration to debug the script, you need to click the green triangle button on the Run and Debug panel, or use the Start Debugging or Run Without Debugging under the Run menu.

如何在VSCode中调试Python?

如何在VSCode中调试Python?

If you want to debug a specific script and configure the program option.

As for whether the play button in the upper right corner can be configured, there are several existing GitHub links you can view.

Allow "Run Python File in Terminal" button to be configurable

VS Code and Python: configure the "Run" button next to the editor tabs

List run configurations from the run button drop-down menu

huangapple
  • 本文由 发表于 2023年3月7日 12:36:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/75658087.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定