0

I have installed python into my command prompt(cmd) btw

command prompt:

C:\Users\*****> python -m pip install termcolor

Collecting termcolor
  Downloading https://files.pythonhosted.org/packages/8a/48/a76be51647d0eb9f10e2a4511bf3ffb8cc1e6b14e9e4fab46173aa79f981/termcolor-1.1.0.tar.gz
Installing collected packages: termcolor
  Running setup.py install for termcolor ... done
Successfully installed termcolor-1.1.0
You are using pip version 9.0.1, however version 19.3.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

C:\Users\*****> python
#going into python now

Python 3.6.3 (v3.6.3:2c5fed8, Oct  3 2017, 17:26:49) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from termcolor import colored
>>> print(colored("hi","green"))

right here is the weird output: [32mhi[0m I have tried python shell and it does not work.(see pic below) Python Shell, which does not work

  • Based on [termcolor's PyPi page](https://pypi.org/project/termcolor/), it does ANSI color formatting, and those are ANSI color sequences, but your command prompt doesn't support them. Were you expecting colored text? If so see [How to print colored text in terminal in Python?](https://stackoverflow.com/q/287871/4518341) For example you might want to use Colorama for better cross-platform support. – wjandrea Dec 14 '19 at 19:22
  • There is only one way that will work always. See answer here. https://stackoverflow.com/questions/54657208/command-prompt-scripting-problem-with-multiple-colors-in-a-batch-file/54658409. Any other technique depends on system configuration if it will work or not. –  Dec 15 '19 at 04:16
  • @Mark, please see the edit I made –  Dec 17 '19 at 01:58

1 Answers1

1

if you are a Windows user, you need to do one extra step. Install the module named colorama. Then, at the top of your code include the code:

from colorama import init
init(autoreset = True)
zx shen
  • 17
  • 2