调试器不会在 VS Code for Python 中的断点处停止 [英] Debugger Not Stopping at Breakpoints in VS Code for Python

查看:33
本文介绍了调试器不会在 VS Code for Python 中的断点处停止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have just installed VS Code and the Python extension, and I have not been able to get the debugger to work. Every time I try to use the debugger, it just skips over any breakpoints that I have set and runs the program like normal.

我在装有 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"文件也如下所示.

I am using VS Code on a Windows 10 PC with Python 3.7.3 and the Python extension installed. I followed the instructions here (https://code.visualstudio.com/docs/python/python-tutorial) to make a test folder called 'hello' in C:\python_work\hello and create a program called 'hello.py' inside that folder. hello.py is shown below. I tried using the debugger both by pressing the green arrow and by pressing F5, but neither seemed to make the debugger work properly. My 'launch.json' file is also shown below.

hello.py:

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

launch.json:

launch.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 文件"一样,而没有在断点处停止.请帮忙!

I expected the bottom bar to turn orange and the program to stop on the second line, allowing me to examine the local and global variables in the preview pane. Instead, the bottom bar stayed orange for 1/2 a second while the program ran as if I had pressed "Run Python File in Terminal," without stopping at the breakpoint. Please help!

推荐答案

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

Setting "justMyCode": false makes it stop at breakpoint:

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

这篇关于调试器不会在 VS Code for Python 中的断点处停止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆