6

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>
Mike Caputo
  • 91
  • 1
  • 7
  • 2
    I personally have not had issue with VSCode on my MacOS. Have you had a gander at the official docs https://code.visualstudio.com/docs/editor/debugging? – Razzle Shazl Feb 03 '21 at 21:35
  • Any useful errors in `TERMINAL` or `PROBLEMS` pane? – Razzle Shazl Feb 03 '21 at 21:38
  • 1
    @RazzleShazl I followed the Python-specific instructions in the official docs for setting up the debugger. That's my second link above. No errors in Terminal or Problems pane. – Mike Caputo Feb 03 '21 at 21:50
  • I'm out of ideas. If it's any help, here is my `launch.json` https://pastebin.com/RAtkYMFJ – Razzle Shazl Feb 03 '21 at 22:05
  • 2
    Please post your launch.json, a sample/portion of your code, and which line exactly did you place a breakpoint. Without these things, this is just guesswork. – Gino Mempin Feb 03 '21 at 23:03
  • start debugging with a simple "Hello World" program. Read the Python docs of VSC, not only the debugger docs – rioV8 Feb 04 '21 at 02:54
  • @Mike Caputo -Have you installed the [python extension](https://code.visualstudio.com/docs/python/python-tutorial#_install-visual-studio-code-and-the-python-extension) in VS Code? In VS Code, Python's debugging function is provided by the Python extension. If it is installed, please try to reinstall it and reload VS Code. – Jill Cheng Feb 04 '21 at 03:17
  • @GinoMempin posted – Mike Caputo Feb 04 '21 at 17:15
  • @JillCheng yes, I have the Python extension installed. I just removed and re-added it, and breakpoints still don't work. – Mike Caputo Feb 04 '21 at 17:18
  • @rioV8 I did read the Python VS Code docs. – Mike Caputo Feb 04 '21 at 17:19
  • @Mike Caputo -Can it stop at a breakpoint when you use other code? I tested the code you provided, and there is a problem at the code "h = hierarchy.Hierarchy()", so it will exit this debugging. – Jill Cheng Feb 05 '21 at 04:27
  • @JillCheng I just did a totally new project, added print("Hello world"), set a breakpoint on that line, and it skipped it. – Mike Caputo Feb 05 '21 at 16:59
  • @Mike Caputo -Have you tested whether python is available? Please enter "python" in cmd outside VS Code to check whether it can enter the python interactive window. – Jill Cheng Feb 08 '21 at 01:23
  • @JillCheng that worked. – Mike Caputo Feb 09 '21 at 18:00
  • @Mike Caputo -How do you debug the code? Could you please provide us with a screenshot of debugging "print("Hello world")" and the information displayed on the VS Code terminal? (Please overwrite the personal information such as the user name in the screenshot.) – Jill Cheng Feb 10 '21 at 06:20
  • @JillCheng I don't have enough reputation to post an image, unfortunately. However, I have posted the text of the terminal output above. – Mike Caputo Feb 11 '21 at 18:02
  • Set the breakpoint and run the python program from terminal? I got this sometime. When I run the program from terminal, the debugging worked. This is just a workaround. If that works, check the configuration again. – T.kowshik Yedida Feb 12 '21 at 06:12
  • @T.kowshikYedida I just tried running from terminal and the breakpoint did not catch. – Mike Caputo Feb 15 '21 at 16:57
  • As I can see in the update 2, the program is returning hello world. That means some other program is running. Not the one you are trying to debug. Do you have any files other than this one? Are you trying to refer that other program in here? – T.kowshik Yedida Feb 15 '21 at 18:00
  • If you are working in a virtual environment you need to switch to the venv interpreter. Not a fan of this not working out of the box. – petey m Jan 10 '23 at 14:20

2 Answers2

6

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

Bobbie E. Ray
  • 635
  • 7
  • 8
1

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.

Jill Cheng
  • 9,179
  • 1
  • 20
  • 25
  • 1
    first of all, I just want to say thanks for all the time you're putting into this. I really appreciate your help. To respond to your answer, I discovered that the Start Debugging thing (as opposed to the green Run button) works as well; the only problem with it is it doesn't actually use breakpoints. It just stops at the first line always. So I can use it for now, but if I want to set a breakpoint in the middle of my code, I can't. Also, I did already try reinstalling the Python extension and reloading VS Code. – Mike Caputo Feb 15 '21 at 16:56
  • @Mike Caputo -This is strange. Have you installed and used other VS Code extensions? Please try to disable them to avoid their influence on the debugging function of python extension. – Jill Cheng Feb 16 '21 at 00:56
  • Reinstalling worked for me! Thank you :) – KoalaD May 17 '23 at 18:12