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

VSCode终端中Python打印ANSI颜色失效问题求助

Fixing ANSI Color Display in VS Code's Integrated Terminal

Hey there! I get it—frustrating when your Python ANSI color code works in repl.it but shows weird escape characters like ←[0m in VS Code's terminal. Let's walk through how to get those colors showing properly.

First, Make Sure Terminal Color Support is Enabled

VS Code might have color support disabled by default (though that's rare these days). Here's how to check:

  • Open VS Code settings: Press Ctrl+, (Windows/Linux) or Cmd+, (Mac).
  • Search for terminal.integrated.enableColors—make sure this option is checked (set to true). This tells the integrated terminal to process ANSI escape codes instead of displaying them as plain text.

Check Your Terminal Profile Configuration

Depending on which terminal you're using (CMD, PowerShell, Bash, etc.), you might need to tweak its settings in VS Code:

  • For Windows CMD: Search for terminal.integrated.profiles.windows in settings. Find the CMD profile and ensure there are no arguments disabling color (like /no_color). The default args (["/d", "/s", "/c"]) are fine.
  • For PowerShell: Similarly, check the PowerShell profile in terminal.integrated.profiles.windows. VS Code's default PowerShell setup should support colors, but if you've customized it, make sure you haven't added flags that turn off color output.
  • For Linux/macOS Bash/Zsh: These terminals usually support ANSI colors out of the box, but double-check that terminal.integrated.profiles.linux or terminal.integrated.profiles.osx don't have any color-disabling flags.

(Optional) Customize ANSI Color Mapping (terminal.ansiColors)

You mentioned the terminal.ansiColors setting—this lets you map ANSI color codes to custom RGB values that match your VS Code theme. Once you've enabled color support, you can tweak this if you want:

  • Search for terminal.ansiColors in settings. You'll see a list of ANSI color names (like black, red, green) paired with RGB hex values.
  • For example, if you want a brighter red for ANSI code 31, you can change "red": "#ff0000" to your preferred hex code. This doesn't fix the "escape characters showing" issue, but it lets you fine-tune how colors look once they're working.

Quick Troubleshooting Tip

If you've changed settings and still don't see colors, restart VS Code. Sometimes terminal settings need a fresh launch to take effect.

Test Your Code Again

Once you've adjusted the settings, run your Python code again:

for i in range(0, 55):
    print(f"\033[{i}mAt {i} THIS happens! \033[0m")

You should now see colored text instead of escape characters. For reference, ANSI codes 30-37 control foreground colors, 40-47 control background colors, and 0 resets everything.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.25 07:10:05