You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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自动关联解释器

    1. 打开命令面板(按Ctrl+Shift+P)
    2. 输入Python: Select Interpreter,选中/home/ian/anaconda3/bin/python3这个解释器
    3. 删除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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.18 07:35:21