Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.5:Colorama无法识别Windows环境_Python_Powershell_Python 3.5_Colorama - Fatal编程技术网

Python 3.5:Colorama无法识别Windows环境

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

我将Python安装从3.4更新为3.5(Windows7Enterprise64位上的CPython64位)。更新之后,colorama停止将ANSI转义序列转换为Win32 API调用,以更改命令行终端颜色

需要显式的
colorama.init(convert=True)
来获得彩色输出。我试图缩小错误范围:

  • 它是在Python 3.5更新后出现的
  • 如果我使用convert选项隐式调用
    init()
    ,就可以解决这个问题
  • 从cmd.exe启动彩色Python脚本可以正常工作
  • 从powershell.exe启动彩色Python脚本将显示所描述的行为
  • 因此,如果从Powershell启动,我假设Python无法识别windows环境?


    有人能重现这种奇怪的行为吗?我该怎么修呢。启用
    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更新之后,这个变量被删除了,所以我也删除了我的变通方法