I have recently started to learn Programming (in Python) and am using VSCode. I have just restarted my computer and now I cannot run a python script in VSCode.
Usually when I have a python script open in VSCode, I can press F5 and my script will run in a Terminal Panel showing the output of my script (PowerShell 7.4.5).
After restarting my computer and trying to run a script in VSCode, the Debugger Panel now opens and after a few seconds I get a pop-up message saying "Timed out waiting for launcher to connect". I don’t remember the debugger panel opening in the past, and my script output would just be displayed in the Terminal Panel. I don’t know if restarting my computer ran an update that switched a setting or maybe I changed something without knowing?
Here are the settings I found that might be causing the problem. I used the stackoverflow links listed below to try to find a solution.
Here is my launch.json config
{
// 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 Debugger: Current File",
"type": "debugpy",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
}
]
}
In my settings.json I have the following two lines that I thought might fix the problem from other questions answered on stackoverflow:
"code-runner.runInTerminal": true
and
"debug.internalConsoleOptions": "neverOpen"
Here are all the settings in what seem to be the Terminal section of the settings.json.
"window.zoomPerWindow": false,
"editor.fontSize": 18,
"terminal.integrated.fontSize": 18,
"python.interpreter.infoVisibility": "always",
"terminal.integrated.defaultLocation": "editor",
"terminal.integrated.tabs.defaultColor": "terminal.ansiGreen",
"window.zoomLevel": 2,
"code-runner.runInTerminal": true,
"debug.internalConsoleOptions": "neverOpen",
"terminal.integrated.automationProfile.windows": {}
I have found and tried the following suggestions on Stackoverflow:
"Then just search code runner run in terminal You’ll see an option to enable Run in Terminal feature turn that on."
I made sure this was set to "true" in my settings.
"code-runner.runInTerminal": true,
Cant run a code in vscode, instead of showing it to me in the terminal section, it sends me to the output section
I have opened a Terminal Panel and changed to the same directory as the script I was running and then tried F5 but it still opened the debugger and then timed out.
Cant run a code in vscode, instead of showing it to me in the terminal section, it sends me to the output section
I tried turning off "Debug Mode" but after restarting VSCode the problem persists.
"debug.internalConsoleOptions": "neverOpen"
How to turn off or close debugging mode in VS-Code
I have made sure the console is set to "integratedTerminal"
"console": "integratedTerminal"
Time out waiting for launcher to connect in VS code
I also tried setting
"console" to "internalConsole"
But still I have the same problem. I have changed my setting back to
"integratedTerminal"
I have made sure to close all open Terminals and restart VSCode but the problem continues.
Timeout when I try to debug a python file in vscode
2
Answers
I have come up with a solution that works for me, but it does not fix the problem, it's more of a workaround. I added a keyboard shortcut to run the "Python: Run Python File" command.
Here is what I did:
Open Keyboard Shortcuts in VSCode - (ctrl + k ctrl + s).
In Keyboard Shortcuts I searched for "Python: Run".
One of the results was - "Python: Run Python File".
I added a Keybinding of (Ctrl + F1) to this command.
Now when I have a python script open in the Editor and press (Ctrl +F1), a new Terminal panel opens and runs my script. There are no errors and the Debugger doesn't open. Just what I wanted.
As oskar mentioned, I could just run the file directly from the Terminal but I like the Keyboard shortcut.
In case anyone was wondering, here are the Commands and the "When clause" to the F5 and (Ctrl + F5) on my VSCode that are giving the "Timed out" error.
I could change my F5 Keybinding to point to the "Python: Run Python File" that is working, but I hope to get this problem fixed at some point in the future so the F5 key will run the debugger normally.
try this
{
"version": "0.2.0",
"configurations": [
{
"name": "Python Debugger: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": false,
"logToFile": true,
"pythonPath": "${workspaceFolder}/venv/bin/python" // replace with the correct python interpreter path
}
]
}