Ubuntu20.04下VS Code提示Python路径无效的解决求助
解决VS Code调试Python时路径无效的问题
以下是几种可行的解决方案:
修正launch.json的配置键名
旧版本VS Code的Python调试器使用pythonPath作为解释器路径的配置键,你当前配置里用的python可能无法被识别。修改后的配置如下:"configurations": [ { "name": "Python: Current File (Integrated Terminal)", "type": "python", "pythonPath": "/home/ian/anaconda3/bin/python3", "request": "launch", "program": "${file}", "console": "integratedTerminal" } ]让VS Code自动关联解释器
- 打开命令面板(按
Ctrl+Shift+P) - 输入
Python: Select Interpreter,选中/home/ian/anaconda3/bin/python3这个解释器 - 删除launch.json里的
python配置项,VS Code会自动使用你选中的解释器路径
- 打开命令面板(按
验证路径的有效性与权限
在终端执行命令确保路径有执行权限:chmod +x /home/ian/anaconda3/bin/python3同时仔细检查路径拼写,确认没有多余空格或符号错误
清理缓存并重启VS Code
关闭VS Code后,删除~/.config/Code/Cache和~/.config/Code/CachedData目录下的缓存文件,再重新打开VS Code尝试调试
内容的提问来源于stack exchange,提问作者Omroth
相关产品推荐
相关产品推荐

