为什么termcolor输出在Windows控制台中控制字符而不是彩色文本?

我刚刚在Windows上安装了Python 2.7的termcolor 。 当我尝试打印彩色文本时,我会获取颜色代码。

from termcolor import colored print colored('Text text text', 'red') 

结果如下:

Windows控制台窗口的屏幕截图:“←31mText text text←[0m”

我在远程pipe理器上获得相同的结果,当我试图作为一个独立的应用程序运行脚本。

要使用termcolor在windows终端中使用的ANSI颜色,您还需要导入/ init colorama ;

 >>> from termcolor import * >>> cprint('hello', 'red') ←[31mhello←[0m >>> import colorama >>> colorama.init() >>> cprint('hello', 'red') hello <-- in red color >>>