1

So I have a code that will create colored text for me. It works when I am testing the program within PyCharm, but when I convert the file to an exe using pyinstaller it gives me a weird printing output.

Code:

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

Output:

[0;34mHello World[0m

This code has to run on someone else's pc, so I can't really download any modules unless there is a way to bundle them with the exe. Is there something I am doing wrong? Is there a way to have color after converting into an exe?

  • 2
    Does your text console support ANSI coloring? – Jongware Feb 13 '20 at 23:46
  • 1
    pycharm's internal console must support ANSI escape sequences, but when you run it from in a terminal as a standalone it's not supported. Windows `cmd` shell doesn't natively support it. There are add-ons for it that will but you'll have do installed and configure them manually. – martineau Feb 13 '20 at 23:50
  • See [How to make win32 console recognize ANSI/VT100 escape sequences?](https://stackoverflow.com/questions/16755142/how-to-make-win32-console-recognize-ansi-vt100-escape-sequences) – martineau Feb 14 '20 at 00:49
  • BTW named lambdas are bad practice. Use a `def` instead, or in this case, don't even bother rolling your own functions - use a library instead. BTW welcome to Stack Overflow! Check out the [tour] and [ask]. – wjandrea Feb 14 '20 at 01:03
  • And yes you can bundle modules in an EXE. How to do that depends on the EXE maker you're using. – wjandrea Feb 14 '20 at 01:08

0 Answers0