Debugger Not Stopping at Breakpoints in VS Code for Python

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-08 12:18:05

问题


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.

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:

{
    // 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
        },
    ]
}

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!


回答1:


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
        },
    ]
}



回答2:


I experienced the same behaviour and was able to solve it by installing the virtual environment of Python in the following way:

[MyProjectFolder] \ venv

by entering the command

python -m venv [MyProjectFolder]\venv

in the console.

VS Code seems to expect exactly that folder structure.

Before I had installed the venv-folder-structure directly in my projects-folder, i.e.

[MyProjectFolder] \ Scripts
[MyProjectFolder] \ Lib
[MyProjectFolder] \ Include
[MyProjectFolder] \ pyvenv.cfg

which did not work and caused exactly the described debug problems.

just as a reference: VS Code version 1.52.1 and Python 3.8.5



来源:https://stackoverflow.com/questions/56794940/debugger-not-stopping-at-breakpoints-in-vs-code-for-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!