29
votes

I'm running the visual studio code tutorial with Python and am unable to connect to the debugger. Google / SO are coming up empty when I search. Usually I use Anaconda with Jupyter, so I'm connecting Visual Studio Code to the python in my activated 3.6 virtual environment. I tried pip installing ptvsd in my virtual environment, but that did not make a difference in what I am seeing.

I would welcome any suggestions. Screenshots included below. launch.json in the bottom screenshot

enter image description here enter image description here

9
I think you have a typo in your launch.json; notice the red squiggle? I think you need a comma following the "console" line. - Brett Cannon
Hi @Brett Cannon, thanks for taking a look at this. I added the comma, which got rid of the squiggle. It has not changed the timeout behavior though, the debug connection is still not made and continues to timeout. - bearcat
At this point you probably need to open an issue at github.com/microsoft/vscode-python to figure out what's going on. Please fill out the issue template when you do and if you can please provide sample code that can reproduce the issue. - Brett Cannon
I should have updated this some time ago. I believe this was happening because I was on Conda 2x. I upgraded to Conda 3x and the debugger has worked since. - bearcat

9 Answers

47
votes

Open the launch.json file and add the following configuration:

{
     "name": "Python: Debug Console",
     "type": "python",
     "request": "launch",
     "program": "${file}",
     "console": "internalConsole"
}

When you specify none internalConsole for the console, it will run the debugger in the debugger console instead of running in the internal or external terminal.

9
votes

I had the same issue, so I added the following line to the settings.json file:

{
    // to fix 'Timeout waiting for debugger connections'
    "python.terminal.activateEnvironment": false
}
8
votes

I had this same problem today. I think it might be a connection problem when the debugger tries to connect to an integrated PowerShell terminal inside Visual Studio. If I change to using an external terminal to run the program then it works okay, and the debugger connects to the external terminal and I can debug perfectly fine. This is my entry for the external terminal launch in launch.json

{
    "name": "Python: Terminal (external)",
    "type": "python",
    "request": "launch",
    "program": "${file}",
    "console": "externalTerminal"
},
7
votes

I had the same issue. fixed by use "integratedTerminal".
ps.my system win7

{
            "name": "Debug",
            "type": "python",
            "request": "launch",
            "program": "${workspaceFolder}/main.Py",
            "console": "integratedTerminal"
}
4
votes

I had the same issue today. The reason was that the debug settings were changed to "Current File (Integrated Terminal). Switching back to "Debug Console" fixed the problem for me.

You can find the settings in the drop-down menu right next to the debug button

4
votes

Change your integrated terminal shell to cmd.exe. This will allow the default launch.json to debug with the Current File (Integrated Terminal) option.

This change has fixed other bugs in my Visual Studio Code + Python integration, such as the double call to Run Python File in Terminal that was frequently required. It was a nice suggestion coming from an internal dialog in version 1.28.2.

2
votes

I think this is going to work fine, I tried it:

"configurations": [
    {
        "name": "Python: Debug Console",
        "type": "python",
        "request": "launch",
        "program": "${file}",
        "console": "integratedTerminal"
    }
  ]
}
1
votes

Add cmd to your environment variables

That helped me to solve the problem.

You need to add the following path to your system variables path.

%SystemRoot%\system32

Good luck, I hope it solved your problem.

0
votes

I got here using WSL.

I tried to restart a debug session and vs code just dropped back to the prompt. When I ran debug again it timed out as per the OP's error.

Solution was to kill the previous debug session in WSL bash (or vs code bash for that matter), one liner:

sudo kill -9 `ps ax | grep python | grep 5678 | cut -d' ' -f1`

Debug should work again.