【问题标题】:Termcolor seems to be working in IDE but not in CMD [duplicate]Termcolor 似乎在 IDE 中工作,但在 CMD 中没有 [重复]
【发布时间】:2020-01-26 11:47:51
【问题描述】:

from termcolor import colored, cprint

cprint("TESTING TERMCOLOR", "red")

此代码在我的 IDE (Pycharm) 中有效,但在我的终端上无效。 在 IDE 中提供彩色输出,但在终端中不提供。 这是终端中的输出:

[31mTESTING TERMCOLOR[0m

【问题讨论】:

  • 请添加您正在使用的操作系统。如果您使用的是 Windows 7,则 CMD 不支持 ANSI 控制代码。像colorama 这样的其他包有一种方法可以将 ANSI 代码转换为 Windows 原生 DLL 调用,所以颜色会显示出来。

标签: python python-3.x termcolor


【解决方案1】:

如果 cmd 你的意思是标准的 windows 终端,我担心 termcolor 在那里不能开箱即用。参见例如Why does termcolor not work in python27 windows? 或 Why does termcolor output control characters instead of colored text in the Windows console?。 https://github.com/tartley/colorama 似乎是让它在那里工作的解决方法

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-04-14
    • 2011-04-14
    • 2015-01-03
    • 2015-03-03
    • 1970-01-01
    • 2018-11-26
    • 2013-11-25
    相关资源
    最近更新 更多