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或命令提示符:- 打开命令面板(Ctrl+Shift+P)
- 输入
Terminal: Select Default Profile - 选择
Command Prompt或PowerShell
修正launch.json配置
若自定义了运行配置,需确保路径格式正确:- 点击运行面板的
创建launch.json文件,选择Python环境 - 检查
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缓存
缓存异常可能导致路径识别错误:- 关闭VSCode
- 删除
%APPDATA%\Code\Cache和%APPDATA%\Code\CachedData文件夹 - 重启VSCode并重新选择Python解释器
检查文件权限
确认当前用户对python.exe所在目录有读取和执行权限:右键文件→属性→安全→验证当前用户的权限设置
内容的提问来源于stack exchange,提问作者Dgatsby
相关产品推荐
相关产品推荐

