Windows – Can’t use python in interactive mode on new msys-git terminal

msysgitpythonterminalwindows

I recently upgraded my laptop, which ran a 32-bit Win7, and my new laptop runs a 64-bit Win7 installation.

I am installing git 2.5.1 from git-scm.com, and the latest python versions (both 3.4.3 and 2.7.10).

During installation, I select to use the new (default) terminal that did not previously come with the installation, and fire up the terminal after installation is completed. When I type in python, however, I don't see any output (cursor moves to the next line as I press enter).

I have tried entering in python commands such as print('hello world'), and the only output I can get is a Syntax error if I type something like a.4. It seems python is running, but I am getting no output. This happens for either version of python that I run.

Python seems to run normally with the alternative Windows cmd-based git, but my normal console wrapper, Console2 doesn't seem to be working correctly, so I can't copy/paste with it very easily.

Any idea as to why the msys console isn't working, or how I can fix this?

Best Answer

From the installation wizard:

"Windows console programs (such as interactive Python) must be launched via <code>winpty</code> to work in MinTTY`

If you want to use the MinTTY terminal that comes with MSys2/Git, you have to launch console programs like Python using winpty.

As of Git for Windows 2.7.1, Winpty is included out of the box, and can be run like so:

winpty /path/to/python.exe

winpty can be found installed at Git\usr\bin

Alternatively, you can always use bash aliasing to write a function in your .bashrc that may do what you want. Here is my solution for working around this new limitation:

function maybe_python34() {
    if [ $# -eq 0 ]; then
        /c/Python34/python.exe -i
    else
       /c/Python34/python.exe $@
    fi
}

alias python=maybe_python34

Note that there are some issues related to using the arrow keys to retrieve command history in the python interactive mode.

Related Question