0

I was advised to use Ansicon to fix a problem with colored text not showing up in the windows terminal. (How to have colored text displayed after converting script into a .exe?) I can't figure out how to use ansicon in my script. Code:

blue = lambda text: '\033[0;34m' + text + '\033[0m'
print(blue('Hello World.'))

I would use colorama but it hasn't been updated past 3.4. When I tried to install via pip it had said that I needed python 3.4 or before. I have installed ansicon but the import command does not want to add it. Does anyone know how to use it?

  • 2
    ansicon has nothing specifically to do with Python so you wouldn't `import` it. It's just something that makes text printed in the Windows `cmd` console respond to ANSI escape sequence (like those that display colored text).The only thing I could find that appear to be instructions for installing it are in its [readme.txt](https://github.com/adoxa/ansicon/blob/master/readme.txt) file. – martineau Feb 14 '20 at 02:21
  • 1
    Did you try [Colorama](https://pypi.org/project/colorama/)? It's a native Python library. ANSICON isn't. – wjandrea Feb 14 '20 at 02:22
  • Also check out this other question: [How to print colored text in terminal in Python?](https://stackoverflow.com/q/287871/4518341) – wjandrea Feb 14 '20 at 02:25
  • Just came back cause I forgot to clarify, you should use something like [termcolor](https://pypi.org/project/termcolor/) or [Blessings](https://pypi.org/project/blessings/) to emit ANSI color sequences, then Colorama to convert from ANSI to Win32. But I also noticed you said Colorama doesn't support 3.5+, which is incorrect. You might be using an old `pip`. – wjandrea Feb 14 '20 at 15:40
  • I checked and I do have an older version of pip installed. I have now updated. I did figure it out however so thank you. – BobDeblonde Feb 16 '20 at 13:57

0 Answers0