PyCharm控制台输出颜色由IDE配色方案(Console Colors)和终端模拟器设置共同控制:Python Console/Debug Console受“Console Colors”配色项影响,需启用“Enable color scheme for standard streams”;Terminal标签页需勾选“Override IDE theme”并手动设色;ANSI转义序列(如\033[31m)生效前提为开启“Enable color output”及“Emulate terminal in output console”。

PyCharm 控制台输出颜色由什么控制?
PyCharm 的控制台(Python Console、Debug Console、Terminal)输出颜色不是靠 Python 代码里的 print() 或 ANSI 转义序列直接决定的,而是由 IDE 自身的配色方案(Color Scheme)和终端模拟器设置共同作用。尤其要注意:
-
Run和Debug的 Python 控制台走的是 PyCharm 内置的“Python Console”引擎,其输出样式受Console Colors配色项控制; -
Terminal标签页走的是系统 shell(如 PowerShell、zsh),它默认忽略 PyCharm 配色,需单独配置 shell 主题或启用“Override IDE theme”; - 如果你在代码里用了
colorama或rich,它们的 ANSI 颜色能否生效,取决于 PyCharm 是否启用了“Emulate terminal in output console”。
如何改 Python Console 的输出文字颜色?
这是最常被问到的场景:运行脚本后,print("hello") 或异常堆栈的颜色太淡、看不清,或想区分 stdout/stderr。操作路径是:File → Settings → Editor → Color Scheme → Console Colors(注意:不是 “Console Font”,也不是 “General” 下的字体设置)
关键点:
PyCharm 2026.2是 JetBrains PyCharm 的指定版本安装包,下载地址指向官方 Windows 安装包直链,可用于旧项目兼容、版本回退和环境测试。
-
Standard output控制正常print()文字颜色; -
Standard error控制sys.stderr和异常 traceback 的底色/文字色; -
Console input是你敲命令时的字体颜色(不影响输出); - 勾选
Enable color scheme for standard streams(在同一个页面顶部)才能让上述设置生效; - 修改后要重启 Python Console(关掉已有控制台标签,再点
Run或Alt+F8打开新 Console)才可见效。
为什么 print("\033[31mred\033[0m") 不变红?
这是典型 ANSI 颜色失效问题,原因通常是:
- PyCharm 默认关闭了 ANSI 解析——必须手动开启:
Settings → Tools → Python Console → Enable color output(勾选此项); - 如果用的是旧版 PyCharm(< 2022.3),该选项可能叫
Use IPython if available+Enable color output,二者都要开; - 在
Run Configuration中启动脚本时,ANSI 颜色默认不生效,因为那是普通 Run 进程,不是 Console;若要支持,得在Run → Edit Configurations → Execution → Emulate terminal in output console打钩; -
rich.print()等库依赖os.environ.get("TERM"),PyCharm 启动时未设该变量,可临时加环境变量TERM=xterm-256color(在 Run Configuration 的Environment variables里填)。
Terminal 标签页的颜色怎么同步 IDE 主题?
Terminal 默认用系统 shell 配色(比如 Windows Terminal 的主题、iTerm2 的 profile),和 PyCharm 主题无关。想让它“看起来像 IDE”:
- 进入
Settings → Tools → Terminal; - 勾选
Override IDE theme(关键!不勾这个,下面所有颜色设置都灰掉); - 然后下方的
Shell font、Foreground color、Background color才可编辑; - 注意:这里改的是整个 Terminal 窗口的底色/字体色,不是单条命令输出的语义颜色(如 git status 的绿色文件名);后者仍由 shell 的
LS_COLORS或git config --global color.ui true控制,PyCharm 不干预。
改完 Console Colors 后记得点右下角 Save as 备份当前方案——PyCharm 升级或重装后,自定义配色容易丢失。另外,Standard error 的背景色如果设得太亮(比如白色),会盖住红色文字,这种细节调一次就知道。

















