【问题标题】:Getting an `stdin is not a tty` error when using python json.tool in git bash在 git bash 中使用 python json.tool 时出现“stdin is not a tty”错误
【发布时间】:2019-01-20 12:45:40
【问题描述】:

我在 Windows 上使用 Git Bash,尝试使用命令行漂亮地打印 JSON 输出。按照this 的回答,我尝试以下操作:

$ echo '{"print": "this"}' | python -m json.tool
stdin is not a tty

我的 Python 版本是 2.7.15 (Anaconda)。

当我使用本机 Windows cmd 尝试相同的操作时,它可以正常工作(但我想使用 Bash)。

【问题讨论】:

    标签: windows python-2.7 git-bash tty


    【解决方案1】:

    echo '{"print": "this"}' | python.exe -m json.tool 在 git bash 会话中会更好地工作吗(将 .exe 添加到 python)。

    那似乎是winpty issue,就像shown here

    【讨论】:

    • 谢谢,添加.exe 后缀似乎有效。原因对我来说仍然很神秘。我添加了一个别名以避免每次都输入它:alias python='winpty python.exe
    • @G.Alon 别名好,我也必须这样做。不要忘记,如果您使用的是足够新的 Windows 10,您可以在 WSL (en.wikipedia.org/wiki/Windows_Subsystem_for_Linux) 上安装和使用(完全 Linux)Git/python,在这种情况下您不会有任何 pty 问题。
    猜你喜欢
    • 2012-09-10
    • 1970-01-01
    • 1970-01-01
    • 2015-11-01
    • 1970-01-01
    • 2021-06-08
    • 2022-11-05
    • 2016-06-24
    • 1970-01-01
    相关资源
    最近更新 更多