8

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?

2 Answers2

11

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.

5

Git utilizes Msys, and there is a better one now, Msys2!

Using it and the modifications that Git-SCM has made to Msys related .profile, .bashrc seems like the way to go to me.

You can now easily upgrade Msys2 with pacman

pacman -Syuu
pacman -S winpty

Git added a nice alias for winpty:

case "$TERM" in
xterm*)
    # The following *.exe programs are known to require a Win32 Console
    # for interactive usage, therefore let's launch them through winpty
    # when run inside `mintty`.
    for name in node python ipython php php5 psql
    do
        case "$(type -p "$name".exe 2>/dev/null)" in
        ''|/usr/bin/*) continue;;
        esac
        alias $name="winpty $name.exe"
    done
    ;;
esac

To get have Git branch show in Prompt copy the file that Git folks put their prompt into and source it in your .bashrc (.git-prompt.sh)

if test -f /etc/profile.d/git-sdk.sh
then
    TITLEPREFIX=SDK-${MSYSTEM#MINGW}
else
    TITLEPREFIX=$MSYSTEM
fi

PS1='\[\033]0;$TITLEPREFIX:${PWD//[^[:ascii:]]/?}\007\]' # set window title
PS1="$PS1"'\n'                 # new line
PS1="$PS1"'\[\033[32m\]'       # change to green
PS1="$PS1"'\u@\h '             # user@host<space>
PS1="$PS1"'\[\033[35m\]'       # change to purple
PS1="$PS1"'$MSYSTEM '          # show MSYSTEM
# PS1="$PS1"'\[\033[33m\]'     # change to brownish yellow
PS1="$PS1"'\[\033[34m\]'       # change to pale blue
PS1="$PS1"'\w'                 # current working directory
if test -z "$WINELOADERNOEXEC"
then
    GIT_EXEC_PATH="$(git --exec-path 2>/dev/null)"
    COMPLETION_PATH="${GIT_EXEC_PATH%/libexec/git-core}"
    COMPLETION_PATH="${COMPLETION_PATH%/lib/git-core}"
    COMPLETION_PATH="$COMPLETION_PATH/share/git/completion"
    if test -f "$COMPLETION_PATH/git-prompt.sh"
    then
        . "$COMPLETION_PATH/git-completion.bash"
        . "$COMPLETION_PATH/git-prompt.sh"
        PS1="$PS1"'\[\033[36m\]'  # change color to cyan
        PS1="$PS1"'`__git_ps1`'   # bash function
    fi
fi
PS1="$PS1"'\[\033[0m\]'        # change color
PS1="$PS1"'\n'                 # new line
PS1="$PS1"'$ '                 # prompt: always $
MSYS2_PS1="$PS1"               # for detection by MSYS2 SDK's bash.basrc
Cas
  • 2,014
Brad Sturtevant
  • 151
  • 1
  • 2