Reputation: 91
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>
Upvotes: 6
Views: 12228
Reputation: 901
In 2024 with Python 3.11 this is still a problem with any code but yours (!) (defined by default justMyCode
setting).
Solution is to add to your launch.json a separate configuration:
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug Python",
"type": "debugpy",
"request": "launch",
"justMyCode": false,
"program": "${file}",
},
... [rest of your file]
Upvotes: 4
Reputation: 1
In my case it was wrong setting of environment variables.
I had a PYTHON_DIR
pointing to python 3.7, PYTHON_DIR
vas used also in Path variable and PYTHON_HOME
pointing to python 3.6
Running file worked well but debugging didn't provide any output in Terminal pane and didn't stop on breakpoint.
Upvotes: -1
Reputation: 824
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
Upvotes: 6
Reputation: 10354
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.
When I click F5
or the "Start Debugging
" button: Debug code it will stay at the breakpoint.
If it still doesn't work, please try to reinstall the Python extension and reload VS Code.
Reference: Python debugging in Visual Studio Code.
Upvotes: 1