Python in VS Code: Not stopping at breakpoints

Viewed 4214

I am trying to debug a simple Python program that reads a CSV and writes a new one in VS Code. When I set a breakpoint, it gets skipped. I am able to use breakpoint() and get the basic Python debugger, but I'd prefer to be able to use the VS Code debugger. I found this SO post and this documentation, but neither resolved the issue. I am on Windows, Python version 3.9.1. I am not an experienced Python developer, so it's very possible I'm missing something obvious, but I have done my fair share of .NET development.

UPDATE 1: launch.json and code

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,
            "justMyCode": false
        }
    ]
}

For the code, I've set breakpoints all over the place trying to get it to work, but here is my main.py. I've tried a breakpoint on the line h.get_approvers():

import adp
import hierarchy
import expensify
import sys

h = hierarchy.Hierarchy()
h.get_approvers()

UPDATE 2: Terminal output when debugging

Loading personal and system profiles took 664ms.
PS C:\Users\...\OneDrive - ZoomInfo\Dev\Sandbox\PyTest> & C:/Python39/python.exe "c:/Users/.../OneDrive - ZoomInfo/Dev/Sandbox/PyTest/main.py"        
Hello world
PS C:\Users\...\OneDrive - ZoomInfo\Dev\Sandbox\PyTest>
2 Answers

Update The issue has been closed and I have received confirmation that it was related to the Python version 3.9.3 (64 bit).

https://github.com/microsoft/vscode-python/issues/15865

Original Post

This has been driving me nuts and needs further investigation, but what I noticed

Python 3.9.3 64 bit >> skips breakpoints
and
Python 3.9.2 64 bit >> works as expected

I have reproduced this multiple times just to ensure that I wasn't just solving a problem with a simple un-/reinstall.

I have raised an issue for this and I'll update this reply as soon as I find the proper root cause, but for now this solves the problem at my end...although not to my satisfaction.

https://github.com/microsoft/vscode-python/issues/15865

I noticed that in the terminal information you provided, the only paths used are "python.exe" and the file "main.py" path.

In VS Code, the debugging function of Python code is provided by Python extensions. Therefore, when debugging python scripts, it will use "python interpreter" (python.exe), "python extension" (.vscode\extensions\ms -python.python-2021.1.502429796\pythonFiles\lib\python\debugpy), and "python script" (.py file).

When I click the green run button in the upper right corner of VS Code, the path displayed on the VS Code terminal is only python.exe and the ".py" file: Run the code and it will not stay at the breakpoint.

enter image description here

When I click F5 or the "Start Debugging" button: Debug code it will stay at the breakpoint.

enter image description here

If it still doesn't work, please try to reinstall the Python extension and reload VS Code.

Reference: Python debugging in Visual Studio Code.

Related