VS Code中‘Timed out waiting for launcher to connect’致调试器无法启动
VS Code Python调试器超时:Timed out waiting for launcher to connect
在VS Code中运行Python调试器时,持续收到「Timed out waiting for launcher to connect」提示,同时被引导打开launch.json文件。当前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", "justMyCode": true } ] }
已尝试以下方案但未解决:
- 删除并重新创建launch.json文件
- 参考相关方案修改launch.json配置
- 回退Python扩展至旧版本
- 卸载并重新安装所有Python扩展
VS Code右下角显示当前Python版本为3.9.0,其他Python功能运行正常,但终端执行调试命令时出现异常输出:
PS C:\Users\alexs\Documents\BEng\Software 1\Formative Assessment\2\SOF1-2022-23-EvenYears-Formative-2\ClosedExamination> \Users\alexs\AppData\Local\Microsoft\WindowsApps\python3.7.exe' 'c:\Users\alexs\.vscode\extensions\ms-python.python-2022.20.2\pythonFiles\lib\python\debugpy\adapter/../..\debugpy\launcher' '57863' '--' 'c:\Users\alexs\Documents\BEng\Software 1\Formative Assessment\2\SOF1-2022-23-EvenYears-Formative-2\ClosedExamination\test_question_4.py' >> 'C:
解决方案
从终端异常输出能看出,调试器调用的是Python 3.7的解释器,但VS Code显示的是3.9.0,这是核心问题。按以下步骤修复:
1. 统一Python解释器版本
- 按下
Ctrl+Shift+P打开命令面板,输入Python: Select Interpreter,选择显示为3.9.0的解释器,确保调试时使用的版本和右下角一致。 - 检查系统环境变量
PATH,将Python 3.9的安装路径移到Python 3.7路径之前(如果存在),避免系统优先调用旧版本。
2. 在launch.json中指定Python路径
在launch.json的配置项中添加pythonPath字段,明确指定3.9.0的完整安装路径,示例如下:
{ "version": "0.2.0", "configurations": [ { "name": "Python: Current File", "type": "python", "request": "launch", "program": "${file}", "console": "integratedTerminal", "justMyCode": true, "pythonPath": "C:/Users/alexs/AppData/Local/Programs/Python/Python39/python.exe" } ] }
注意替换为你实际的Python 3.9安装路径。
3. 清理Windows Apps中的旧Python快捷方式
打开路径C:\Users\alexs\AppData\Local\Microsoft\WindowsApps,找到python3.7.exe相关的快捷方式,删除或重命名,防止VS Code误调用旧版本解释器。
4. 验证调试命令格式
手动在终端输入正确的调试命令,确保路径和引号格式正确,示例:
& "C:/Users/alexs/AppData/Local/Programs/Python/Python39/python.exe" "c:/Users/alexs/.vscode/extensions/ms-python.python-2022.20.2/pythonFiles/lib/python/debugpy/launcher" 57863 "--" "c:/Users/alexs/Documents/BEng/Software 1/Formative Assessment/2/SOF1-2022-23-EvenYears-Formative-2/ClosedExamination/test_question_4.py"
如果手动命令能正常运行,说明问题出在VS Code的解释器配置上,重新选择解释器即可解决。
内容的提问来源于stack exchange,提问作者Let A be the Unknown
相关产品推荐
相关产品推荐

