python - Termcolor“彩色”输出奇怪的字符
问题描述
我已经将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"))
解决方案
如果您是 Windows 用户,则需要多做一步。安装名为 colorama 的模块。然后,在代码的顶部包含以下代码:
from colorama import init init(autoreset = True)
推荐阅读
- php - 如何在 _e() wordpress 函数中设置文本样式?
- sql - SqlServer - 应该返回相同数量的行吗?除了与左连接
- vue.js - 在 vue 2.5.2 中安装 sass 后出现 css-loader 错误
- java - IntelliJ 中的依赖关系没有得到解决
- c++ - 我们应该在函数的参数中使用还是不使用常量类型引用?
- docker - 即使已安装,在 Docker 容器中也找不到“json-server”命令
- flutter - VISUAL STUDIO CODE 工作时 scrcpy 不工作
- windows - 链接栏和搜索栏的区别
- python - 如何将 jpeg 数据集文件夹转换为一种 HDF5 字节格式(Python)?或者有没有更好的方法来压缩数据集?
- python - 使用字典将表情符号替换为文本