James Kanze James Kanze - 1 month ago 20
Python Question

Invoking python under CygWin on Windows hangs

Installing a new Windows system, I've installed CygWin and 64
bit Python (2.7.3) in their default locations (

c:\cygwin
and
c:\Python27\python
), and added both the CygWin bin and the
Python directory to my path (in the user variable PATH). From
the normal command window, Python starts up perfectly, but when
I invoke it from
bash
in the CygWin environment, it hangs,
never giving my the input prompt.

I've done this on other machines, previously, but always with
older versions of Python (32 bits) and CygWin, and with Python
in a decidely non-standard location. Has anyone else had this
problem, or could someone tell me what it might be due to?

Answer

The problem is that due to the way that the Cygwin terminal (MinTTY) behaves, the native Windows build of Python doesn't realize that stdout is a terminal device -- it thinks it's a pipe, so it runs in non-interactive mode instead of interactive mode, and it fully buffers its output instead of line-buffering it.

The reason that this is new is likely because in your previous Cygwin installation, you didn't have MinTTY, and the terminal used was just the standard Windows terminal.

In order to fix this, you either need to run Python from a regular Windows terminal (Cmd.exe), or install the Cygwin version of Python instead of a native Windows build of Python. The Cygwin version (installable as a package via Cygwin's setup.exe) understands Cygwin terminals and acts appropriately when run through MinTTY.

If the particular version of Python you want is not available as a Cygwin package, then you can also download the source code of Python and build it yourself under Cygwin. You'll need a Cygwin compiler toolchain if you don't already have one (GCC), but then I believe it should compile with a standard ./configure && make && make install command.