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, Style print Fore.RED + "My Text is Red"
and it returns the ANSI charaters....
esc[31mMy Text is Red
This isn`t what I expected. Am I doing something wrong.
Thanks.
On Windows, Colorama works by replacing sys. stdout and sys. stderr with proxy objects, which override the . write() method to do their work.
The Python "ModuleNotFoundError: No module named 'colorama'" occurs when we forget to install the colorama module before importing it or install it in an incorrect environment. To solve the error, install the module by running the pip install colorama command.
Changing text color In colorama, the font color or the text color is referred to as Fore(stands for foreground). To change the font color, start by importing the module. Then, in the print statement, mention the color you want to use.
I had this same issue on Windows 7 x64, I finally got the colors working without having to install anything new just by adding the argument convert=True
to the init call.
from colorama import init, Fore, Back, Style init(convert=True) print(Fore.RED + 'some red text')
I've never had success getting colors working in Windows cmd.exe without patching it with Ansicon. After patching, ANSI color codes will work without needing to use something like colorama (which didn't work for me either).
To patch cmd.exe with Ansicon, do the following:
ansicon.exe –i
via: https://stackoverflow.com/a/4749307/191902
Also, if you have an NVidia graphics card, you might need to set the environment variable "ANSICON_EXC" to "nvd3d9wrap.dll".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With