Termcolor installs succesfully but doesn't seem to work properly

111 Views Asked by At

I started learning Python recently. I am trying to use the termcolor module. I installed it (latest version) successfully. But it doesn't seem to work on Pycharm. I apply the example code that is provided in the module download page (as listed below) and I get only one colored word as output (as in the image). Do you know what can cause this?

code page: https://pypi.org/project/termcolor/

import sys

from termcolor import colored, cprint

text = colored("Hello, World!", "red", attrs=["reverse", "blink"])
print(text)
cprint("Hello, World!", "green", "on_red")

print_red_on_cyan = lambda x: cprint(x, "red", "on_cyan")
print_red_on_cyan("Hello, World!")
print_red_on_cyan("Hello, Universe!")

for i in range(10):
    cprint(i, "magenta", end=" ")

cprint("Attention!", "red", attrs=["bold"], file=sys.stderr)

Output of the code above

I expected to have all the colors and formatting listed in the code to work.

2

There are 2 best solutions below

0
MUA Star On

your code run correctly in vcs like this :link

also use colorama library for showing colors in Pycharm terminal

0
MUA Star On

I found a way in colored switch parameter force_color to True

such as

print(colored('answer' , 'red' , None , None , no_color = False , force_color = True))