Python 3.5:Colorama无法识别Windows环境
我将Python安装从3.4更新为3.5(Windows7Enterprise64位上的CPython64位)。更新之后,colorama停止将ANSI转义序列转换为Win32 API调用,以更改命令行终端颜色 需要显式的Python 3.5:Colorama无法识别Windows环境,python,powershell,python-3.5,colorama,Python,Powershell,Python 3.5,Colorama,我将Python安装从3.4更新为3.5(Windows7Enterprise64位上的CPython64位)。更新之后,colorama停止将ANSI转义序列转换为Win32 API调用,以更改命令行终端颜色 需要显式的colorama.init(convert=True)来获得彩色输出。我试图缩小错误范围: 它是在Python 3.5更新后出现的 如果我使用convert选项隐式调用init(),就可以解决这个问题 从cmd.exe启动彩色Python脚本可以正常工作 从powershell
colorama.init(convert=True)
来获得彩色输出。我试图缩小错误范围:
init()
,就可以解决这个问题有人能重现这种奇怪的行为吗?我该怎么修呢。启用
convert
将在Linux上出现问题。我搜索了colorama 0.3.3源代码,找到了用于确定它是否运行windows的代码:
...
on_windows = os.name == 'nt'
on_emulated_windows = on_windows and 'TERM' in os.environ
# should we strip ANSI sequences from our output?
if strip is None:
strip = on_windows and not on_emulated_windows
self.strip = strip
# should we should convert ANSI sequences into win32 calls?
if convert is None:
convert = on_windows and not wrapped.closed and not on_emulated_windows and is_a_tty(wrapped)
self.convert = convert
....
一个条件是,如果存在术语
环境变量集。不幸的是,我的PowerShell控制台声称是cygwin终端
但我从来没有自己安装过cygwin。所以我必须搜索哪个程序安装了cygwin并在我的PowerShell中注册了它
编辑:
我发现,PoSh Git注册了一个TERM
变量。作为一种解决方法,我在加载PoSh Git后立即添加了一行rm env:TERM
在一次漂亮的Git更新之后,这个变量被删除了,所以我也删除了我的变通方法