首页 > 解决方案 > 调试器不会在 VS Code for Python 中的断点处停止

问题描述

我刚刚安装了 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
        },
    ]
}

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

标签: pythonvisual-studio-codevscode-debugger

解决方案


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

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

推荐阅读