26
votes

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!

6
It's working fine for me. What is being sent to the terminal to launch the debugger? - Brett Cannon
Something like this: cd c:\python_work\hello && cmd /C "set "PYTHONIOENCODING=UTF-8" && set "PYTHONUNBUFFERED=1" && C:\Python\python.exe c:\Users\RohanPC\.vscode\extensions\ms-python.python-2019.6.22090\pythonFiles\ptvsd_launcher.py --default --client --host localhost --port 49389 c:\python_work\hello\hello.py " - rogo8888
If you could file a bug at github.com/microsoft/vscode-python and provide a GitHub project or zipfile of a folder that can reproduce the problem then we can have a look and see if we can figure out what's going on. - Brett Cannon
I just reinstalled Windows and the problem got solved! Thank you so much for your help. - rogo8888
It's generally regarded as good practice to reinstall Windows at least twice a day. - kmiklas

6 Answers

39
votes

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

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

2
votes

If you're using a pytest-cov module you might also wanna have a look at pytest configuration settings note:

Note If you have the pytest-cov coverage module installed, VS Code doesn't stop at breakpoints while debugging because pytest-cov is using the same technique to access the source code being run. To prevent this behavior, include --no-cov in pytestArgs when debugging tests, for example by adding "env": {"PYTEST_ADDOPTS": "--no-cov"} to your debug configuration.

See an example configuration file (launch.json) below:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Debug Tests",
            "type": "python",
            "request": "test",
            "console": "integratedTerminal",
            "justMyCode": false,
            "env": {"PYTEST_ADDOPTS": "--no-cov"}
        }
    ]
}
0
votes

I had the same problem having upgraded from Python version 3.7 to version 3.9. I later found out that the old version was 32 bit, and the new version I upgraded to was 64 bit, which apparently caused the issues. Uninstalling the 64 bit version and installing the 32 bit version of Python 3.9 solved my problem, and I was then able to use the Visual Studio Code breakpoint functionality again.

0
votes

I recently found out ( 5th May 2020) that using Python 3.9 as interpreter the breakpoints were not hitting. Install 3.8 and it will start working again.

0
votes

Downgrading from Python 3.9 to 3.8 worked for me.

VC Code 1.56.2 ignored breakpoints running Python 3.9 64-bit on Windows 10 version 20H2. Installing Python 3.8.10 64-bit fixed the problem. I just needed to select the Python 3.8.10 interpreter within VS code and it now recognizes breakpoints. No changes to the configuration file were needed, for example, I did not need "justMyCode": false

I realize this is an old question, but my google search lead me to it. Many of the previous answers no longer apply. So I'm posting this fix for others who land here in 2021 trying to use 3.9.