调试器不会在 Python 的 VS 代码中的断点处停止

新手上路,请多包涵

我刚刚安装了 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 如下所示。我尝试通过按绿色箭头和按 F5 来使用调试器,但似乎都无法使调试器正常工作。我的“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
        },
    ]
}

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

原文由 rogo8888 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 1k
1 个回答

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

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

原文由 Ashish 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题