python - 调试器不会在 VS Code for Python 中的断点处停止

标签 python visual-studio-code vscode-debugger

我刚刚安装了 VS Code 和 Python 扩展,但我一直无法让调试器工作。每次我尝试使用调试器时,它都会跳过我设置的任何断点并像往常一样运行程序。

我在装有 Python 3.7.3 和 Python 扩展的 Windows 10 PC 上使用 VS Code。我按照此处的说明( https://code.visualstudio.com/docs/python/python-tutorial )在 C:\python_work\hello 中创建一个名为“hello”的测试文件夹,并在该文件夹中创建一个名为“hello.py”的程序。 hello.py 如下所示。我尝试通过按绿色箭头和按 F​​5 来使用调试器,但似乎都没有使调试器正常工作。我的“launch.json”文件也如下所示。

你好.py:

msg = "Hello World!"
print(msg) # Breakpoint

启动.json:
{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "stopOnEntry": true
        },
    ]
}

我希望底部栏变成橙色,程序停止在第二行,让我可以检查预览 Pane 中的局部和全局变量。相反,当程序运行时,底部栏保持橙色 1/2 秒,就好像我按下了“在终端中运行 Python 文件”一样,而没有在断点处停止。请帮忙!

最佳答案

设置 "justMyCode": false使它在断点处停止:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Debug Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "stopOnEntry": true,
            "justMyCode": false
        },
    ]
}

关于python - 调试器不会在 VS Code for Python 中的断点处停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56794940/

相关文章:

visual-studio-code - 配置 launch.json、task.json 和 settings.json 以在 VS Code 中使用 git bash 作为默认终端进行调试?

javascript - "rejected promise not handled within 1 second"vscode 扩展 API

reactjs - 如何调试 React 加载项

python - 如何解决django插入mysql报错

python - 解析XML、日期格式(PT0H0M0S、PT2920H0M0S)

python - 读取 csv(逗号分隔文件),值在引号中,逗号作为小数点

python - 使用 VSCode 在 python 中突出显示初始变量赋值

python - 如何将并行子进程的输出写入不同的文件

visual-studio-code - 如何通过在 VSCode 中按键绑定(bind)来查找命令

使用 VSCode 调试自定义 Yeoman 生成器