VS Code远程容器调试Python报错‘Debug Adapter Executable not provide’排查
解决VS Code容器调试Python时的"Debug Adapter Executable not provide"错误
以下是可能的问题点及对应解决方法:
1. 容器内未安装调试适配器依赖
VS Code的Python容器调试需要依赖debugpy(或旧版ptvsd),容器内未安装该依赖时,会出现找不到调试可执行文件的错误。
在你的Dockerfile中添加安装命令:
RUN pip install debugpy
2. tasks.json的docker-run任务缺少调试配置
原tasks.json中的docker-run: debug任务未指定调试端口映射和适配器启动路径,需要补充配置:
修改后的tasks.json相关部分:
{ "type": "docker-run", "label": "docker-run: debug", "dependsOn": ["docker-build"], "python": { "file": "app.py", "portMappings": [{"hostPort": 5678, "containerPort": 5678}], "debuggerPort": 5678, "debuggerPath": "/usr/local/bin/python -m debugpy" } }
portMappings:打通本地与容器的调试端口,确保调试信号正常传输debuggerPath:指定容器内调试适配器的启动命令,需与容器内Python的实际路径匹配(若你的Python路径不是/usr/local/bin/python,需对应修改)
3. launch.json配置可优化为直接远程附着
原launch.json使用docker类型的调试配置,也可切换为更稳定的python远程附着模式:
修改后的launch.json:
{ "configurations": [ { "name": "Python: Remote Attach", "type": "python", "request": "attach", "connect": { "host": "localhost", "port": 5678 }, "pathMappings": [ { "localRoot": "${workspaceFolder}", "remoteRoot": "/app" } ] } ] }
使用该配置时,需确保容器内代码通过debugpy启动,可在Dockerfile的CMD或ENTRYPOINT中设置:
CMD ["python", "-m", "debugpy", "--listen", "0.0.0.0:5678", "--wait-for-client", "app.py"]
4. 检查VS Code扩展状态
确保本地VS Code已安装Python和Docker扩展,进入远程容器环境后,确认Python扩展已正常激活(可在扩展面板的"已安装"列表中查看)
内容的提问来源于stack exchange,提问作者Jim
相关产品推荐
相关产品推荐

