1

I am trying to learn how to use break points.

As you can see in below screenshot, the program didn't stop at break point and the variables window is empty.

I press the button in orange circle. I have also tried press F5 Start debugging. Both have same result.

What could be the problem?

enter image description here

Here is my code. There is no error message. The program run from line 1 to line 9 without error.

a = 33
b = 200
if b>a:
    print("b is larger than b")

c = 1000
d = 9999
if d>c:
    print("d is larger than c")

Here is my debug configuration 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",
            "justMyCode": true
        }
    ]
}
10
  • Please post the code and error as text, not an image. Commented Dec 22, 2023 at 12:28
  • Could you post a higher resolution image?
    – Niko Fohr
    Commented Dec 22, 2023 at 12:59
  • Also, could you mark the button you pressed to start the debug mode on the image?
    – Niko Fohr
    Commented Dec 22, 2023 at 13:02
  • I could not reproduce the behaviour on my VS Code (v.1.85.1 on Ubuntu). It could be something related to launch.json file. See, for example stackoverflow.com/a/75978382/3015186
    – Niko Fohr
    Commented Dec 22, 2023 at 13:49
  • 1
    @starball Yep. Looking at the file paths, he has created a VSC workspace directory with the test.py file INSIDE the python interpreter directory with the python.exe. First place the VSC workspace OUTSIDE the python interpreter directory. Your file is seen as part of the python libs, it is INSIDE the python interpreter directory, you have the justMyCode:true
    – rioV8
    Commented Dec 22, 2023 at 21:56

4 Answers 4

1

Looking at the file paths, you have created a VSC workspace directory with the test.py file INSIDE the python interpreter directory with the python.exe.

First place the VSC workspace OUTSIDE the python interpreter directory.

Your file test.py is seen as part of the python libs, it is INSIDE the python interpreter directory, you have the justMyCode:true

1
  • Thank you. After change the directory, the debug mode is working.
    – Mark
    Commented Jan 4 at 9:14
0

You are placing the stop in the loop line. If you want to check the values before it enters and does the whole loop, you need to place it in the line before, if not, you are stopping the debug in the loop exit, and you program ends when your loop ends.

1
  • I have tried added breakpoint on every line. The debugger just don't stop on any. I guess I missed some configuration in my visual studio code.
    – Mark
    Commented Dec 22, 2023 at 13:41
-1

I don't know the true cause but I found a workaround.

I create a Jupyter Notebook (test.ipynb) then copy my code to one of the cell. Then I press "Debug Cell" as in below screen capture. Then the debug mode and breakpoints are working as expected.

enter image description here

2
  • This doesn't answer your question and shouldn't be posted as an answer
    – possum
    Commented Dec 22, 2023 at 15:12
  • 4
    @possum I think this is fine. there is no law here that says that workarounds are definitively illegitimate answers. in fact, many people find workarounds useful.
    – starball
    Commented Dec 22, 2023 at 19:50
-2

It seems that you create a working area in the Python directory.

enter image description here

Modifying launch.json justMyCode value to false can make debugging stop at the breakpoint.

But the correct approach should be to create a working area outside the Python directory.

1
  • what's the point of posting this? it says essentially the same thing as riov8's answer post.
    – starball
    Commented Dec 23, 2023 at 8:54

Not the answer you're looking for? Browse other questions tagged or ask your own question.