VS Code运行C#代码仅显示Run Tests选项,点击运行报错如何解决
问题描述
我在VS Code中看到的菜单如下:
点击右上角三角按钮运行代码时返回报错,报错界面如下:

请问该如何解决这个问题?
解决建议
配置正确的Python解释器
打开VS Code命令面板(快捷键:Ctrl+Shift+P/Cmd+Shift+P),输入Python: Select Interpreter,选择本地已安装的Python版本。如果列表为空,先确认Python已安装并添加到系统环境变量。修复终端命令识别问题
从报错来看,终端无法识别python命令,多数是因为系统默认Python命令为python3:- 打开VS Code设置(
Ctrl+,/Cmd+,),搜索python.pythonPath,将路径改为你的Python3可执行文件路径(比如Linux/macOS的/usr/bin/python3,Windows的C:\Python3xx\python.exe)。 - 临时解决方案:Linux/macOS终端执行
alias python=python3;Windows PowerShell执行Set-Alias python python3,重启终端后生效。
- 打开VS Code设置(
检查运行配置文件
查看项目下的.vscode/launch.json文件(无则创建),确保配置中的解释器路径正确,示例配置:{ "version": "0.2.0", "configurations": [ { "name": "Python: Current File", "type": "python", "request": "launch", "program": "${file}", "console": "integratedTerminal", "pythonPath": "${command:python.interpreterPath}" } ] }重启VS Code
完成配置后,打开命令面板输入Reload Window重载窗口,再尝试运行代码。
内容的提问来源于stack exchange,提问作者Gabriela R
相关产品推荐
相关产品推荐

