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

VSCode运行按钮无法输出Python脚本问题求助

解决VSCode运行Python时提示找不到解释器的问题

问题重现

点击VSCode运行按钮后输出:

C:/Users/user/AppData/Local/Programs/Python/Python311/python.exe "c:/Users/ogdar/VSCODE FOLDERS/Lesson01/hello.py"
-bash: C:/Users/user/AppData/Local/Programs/Python/Python311/python.exe: No such file or directory

实际该路径下存在python.exe,直接在终端运行绝对路径可正常执行,切换VSCode默认解释器后问题依旧。

解决方案

  • 切换终端类型适配路径格式
    错误输出使用的是bash终端,Windows风格的C:/路径在bash中无法被正确识别。可以将VSCode默认终端切换为PowerShell或命令提示符:

    1. 打开命令面板(Ctrl+Shift+P)
    2. 输入Terminal: Select Default Profile
    3. 选择Command Prompt或PowerShell
  • 修正launch.json配置
    若自定义了运行配置,需确保路径格式正确:

    1. 点击运行面板的创建launch.json文件,选择Python环境
    2. 检查pythonPath或command字段,使用标准Windows路径,示例:
    {
        "version": "0.2.0",
        "configurations": [
            {
                "name": "Python: 当前文件",
                "type": "python",
                "request": "launch",
                "program": "${file}",
                "console": "integratedTerminal",
                "pythonPath": "C:/Users/user/AppData/Local/Programs/Python/Python311/python.exe"
            }
        ]
    }
    
  • 清除VSCode缓存
    缓存异常可能导致路径识别错误:

    1. 关闭VSCode
    2. 删除%APPDATA%\Code\Cache和%APPDATA%\Code\CachedData文件夹
    3. 重启VSCode并重新选择Python解释器
  • 检查文件权限
    确认当前用户对python.exe所在目录有读取和执行权限:右键文件→属性→安全→验证当前用户的权限设置

内容的提问来源于stack exchange,提问作者Dgatsby

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.10 05:03:12