python - Winpty 和 Git Bash

标签 python git-bash winpty

我遇到了与 Python not working in the command line of git bash 相同的问题,在 Git Bash 中,当我键入 Python 时,它只是挂起。

但是,输入 winpty python 效果很好。

winpty 到底是什么?为什么上面的命令有用?

最佳答案

winpty是一个 Windows 软件包,提供类似于 Unix pty-master 的接口(interface),用于与 Windows 控制台程序进行通信。

这就是为什么您需要它作为 described here :

The software works by starting the winpty-agent.exe process with a new, hidden console window, which bridges between the console API and terminal input/output escape codes. It polls the hidden console's screen buffer for changes and generates a corresponding stream of output.

rprichard/winpty提及:

The package consists of a library (libwinpty) and a tool for Cygwin and MSYS for running Windows console programs in a Cygwin/MSYS pty.

详见“mintty/mintty Tips”:

When interacting with programs that use a native Windows API for command-line user interaction (“console mode”), a number of undesirable effects are observed; this is the pty incompatibility problem and the character encoding incompatibility problem.
This basically affects all programs not compiled in a cygwin or msys environment (and note that MinGW is not msys in this context).

As a workaround, you can use winpty as a wrapper to invoke the Windows program.


所以:

Why do many tools work in plain CygWin but some of them also need winpty?

这是在 msys2/MINGW-packages issue 2645 中提出的(专门针对 Python)

there's a non-zero cost associated with using winpty, and most of the time, mintty works fine anyway.
Your problem stems from trying to use mingw python which is a native windows build, and hence expects it to be used from a windows console.
mintty uses pipes for input/output, so it doesn't look like a proper terminal to most programs.

On the other hand, if you use msys2 (or cygwin) python (.e.g /usr/local/bin/python2), everything just works.

(使用 msys2/MINGW-packages PR 2675 ,python3 正确检测到终端)

关于python - Winpty 和 Git Bash,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48199794/

相关文章:

python - Scrapy 不会回调除默认​​ 'parse' 之外的其他函数

python - 想要找到轮廓-> ValueError : not enough values to unpack (expected 3, got 2),出现这个

python - 将多个 pandas 列转换为 json

python - 从 For 循环输出中逐列写入 CSV 文件

Bash:${$(mycommand)%suffix} 无法从 mycommand 输出中删除后缀

git-bash - Git Bash 的确切含义是什么?

tomcat - Ctrl-c 不使用 Git Bash 停止 Tomcat