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

咨询:VS Code运行代码后输出区无正常内容该如何修复

Hey there! Let's troubleshoot why your Code Runner is only displaying exception messages and not regular output. I've run into similar issues before, so here are some tried-and-true fixes to try:

1. Switch Code Runner to run in the terminal

By default, Code Runner might use the VS Code "Output" panel, which can sometimes fail to capture standard output correctly. Here's how to change it:

  • Open VS Code settings with Ctrl+, (Windows/Linux) or Cmd+, (Mac)
  • Search for Code Runner: Run In Terminal and check the box. This will make your code run in the integrated terminal instead, which reliably shows both regular output and exceptions.

2. Ensure VS Code is using your Python 3.7 interpreter

Even if Python 3.7 is installed, VS Code might be pointing to a different version:

  • Look at the bottom-left corner of VS Code—you'll see the current Python interpreter version (e.g., Python 3.9.6). Click on it.
  • Select your Python 3.7 installation from the dropdown list. If it doesn't show up, use the command palette (Ctrl+Shift+P / Cmd+Shift+P), type Python: Select Interpreter, and pick Python 3.7 manually.

3. Fix output buffering with the -u flag

Sometimes Python buffers output, so regular print statements don't show up until the program finishes (or the buffer fills up). To disable this:

  • Open Code Runner's settings and search for Code Runner: Executor Map, then click "Edit in settings.json"
  • Update the Python entry to include the -u flag, like this:
    "code-runner.executorMap": {
        "python": "python3.7 -u"
    }
    
    The -u flag forces unbuffered output, so your print statements will show up right away.

4. Double-check your code's output logic

  • Make sure you're actually printing output with print()—if you have a function that returns a value but you don't call print(your_function()), you won't see anything.
  • If you're using sys.stdout.write(), add sys.stdout.flush() after it to push the output to the terminal immediately.

5. Check the Output panel filters (if you're still using it)

If you prefer sticking with the Output panel instead of the terminal:

  • Click the dropdown menu at the top-right of the Output panel (it says "Code Runner" by default)
  • Make sure no filters are applied that would hide regular output—reset any custom filters if you've set them.

One of these steps should get your regular output showing up alongside exceptions. Let me know if you hit any snags!


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.14 07:11:37