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

Termcolor在VS Code正常显示红色,PyCharm中失效的问题求助

解决PyCharm中termcolor无法显示彩色文本的问题

方案一:更换PyCharm终端的Shell

PyCharm默认的cmd.exe对ANSI颜色支持不佳,换成PowerShell即可解决:

  • 打开PyCharm设置(快捷键Ctrl+Alt+S)
  • 找到Tools > Terminal
  • 把Shell path改成powershell.exe(Windows),或系统自带的支持ANSI的终端(比如macOS/Linux的bash/zsh)
  • 重启终端后再运行代码

方案二:强制termcolor输出彩色

修改代码时添加force_color=True参数,强制生成ANSI转义序列:

from termcolor import colored

print(colored("test test test test", "red", force_color=True))

方案三:配置Run窗口的终端模拟

如果用Run窗口而非Terminal窗口运行代码:

  • 打开Run > Edit Configurations
  • 选中你的Python运行配置,勾选Emulate terminal in output console
  • 确保PyCharm版本在2020.3及以上,旧版本可能不支持颜色渲染

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.24 07:27:31