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

VS Code运行C#代码仅显示Run Tests选项,点击运行报错如何解决

问题描述

我在VS Code中看到的菜单如下:
菜单截图

点击右上角三角按钮运行代码时返回报错,报错界面如下:
报错截图1
报错截图2

请问该如何解决这个问题?

解决建议
  • 配置正确的Python解释器
    打开VS Code命令面板(快捷键:Ctrl+Shift+P / Cmd+Shift+P),输入Python: Select Interpreter,选择本地已安装的Python版本。如果列表为空,先确认Python已安装并添加到系统环境变量。

  • 修复终端命令识别问题
    从报错来看,终端无法识别python命令,多数是因为系统默认Python命令为python3:

    1. 打开VS Code设置(Ctrl+, / Cmd+,),搜索python.pythonPath,将路径改为你的Python3可执行文件路径(比如Linux/macOS的/usr/bin/python3,Windows的C:\Python3xx\python.exe)。
    2. 临时解决方案:Linux/macOS终端执行alias python=python3;Windows PowerShell执行Set-Alias python python3,重启终端后生效。
  • 检查运行配置文件
    查看项目下的.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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.06 08:52:51