【发布时间】:2020-04-07 19:05:41
【问题描述】:
我已将 python 安装到我的命令提示符中(cmd)顺便说一句
命令提示符:
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"))
【问题讨论】:
-
基于termcolor's PyPi page,它进行ANSI颜色格式化,这些是ANSI颜色序列,但你的命令提示符不支持它们。您期待彩色文本吗?如果是这样,请参阅 How to print colored text in terminal in Python? 例如,您可能希望使用 Colorama 以获得更好的跨平台支持。
-
只有一种方法可以一直有效。在这里查看答案。 stackoverflow.com/questions/54657208/…。任何其他技术是否可行都取决于系统配置。
-
@Mark,请查看我所做的编辑