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
相关产品推荐
相关产品推荐

