Colorama for Python, Not returning colored print lines on Windows

前端 未结 7 1563
南笙
南笙 2020-12-01 18:16

I\'ve installed colorama for python. I\'ve imported the module as follows:

import colorama
from colorama import init
init()
from colorama import Fore, Back,          


        
7条回答
  •  春和景丽
    2020-12-01 18:52

    I know I'm late, but this will hopefully help anyone still looking for the answer.

    Stating from Colorama's documentation on PyPI:

    Colorama can be used happily in conjunction with existing ANSI libraries such as Termcolor

    from colorama import init
    from termcolor import colored
    
    # use Colorama to make Termcolor work on Windows too
    init()
    
    # then use Termcolor for all colored text output
    print(colored('Hello, World!', 'green', 'on_red'))
    

    This worked for me, on Anaconda Prompt (essentially cmd.exe) on Windows 10 64-bit.

    Colorama's native ANSI sequences don't seem to work for some reason. An external ANSI library (i.e. Termcolor) did the trick for me.

提交回复
热议问题