6

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?

Casey Kuball
  • 456
  • 5
  • 18

2 Answers2

9

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.

Casey Kuball
  • 456
  • 5
  • 18
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
  • 1,944
  • 2
  • 19
  • 42
Brad Sturtevant
  • 151
  • 1
  • 2
  • So you are suggesting installing Msys2 either before or after installing Msys-git? Also, can you clarify what this means?: `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)` – Casey Kuball Nov 07 '16 at 17:26
  • @cascer1 [reply 1 of 2] I do have both [Git for Win] (https://git-scm.com/download/win) and [Msys2] (https://sourceforge.net/p/msys2/wiki/MSYS2%20installation/) installed. In Msys2 you can install Git manually `pacman -S git git-flow`. The prompt I like is `User@BHost MINGW64 ~/Develop/src/my-git-clone (develop)`. The `(develop)` part is what's added. When you enter a dir with a .git sub dir (Git project) it will display current Git branch (develop). The folks at Git have enhanced the prompt in Msys by creating a file `GitInstallDir\etc\profile.d\git-prompt.sh`. – Brad Sturtevant Nov 10 '16 at 07:09
  • @cascer1 [reply 2 of 2] You can add Git's prompt (to Msys2) by referencing git-prompt.sh in your ~/.bashrc, or copy/rename file to ~/.bash_prompt, then in ~/.bashrc I added `. "${HOME}/.bash_prompt.sh"`. Also can just copy both alias and prompt as displaied above. Git for Win comes with winpty but Msys2 does not, so did `pacman -S winpty`. Have not tested Msys2 without Git for Windows, but Msys2 is working well with GitHub. I am treating Git for Win startup files (.bashrc, etc.) as examples of how to setup my own. – Brad Sturtevant Nov 10 '16 at 07:10
  • @BradSturtevant Uhh, I'm not sure how to reply to this. All I did was edit your post to make it a little easier to read ;). You can see what I changed [here](http://superuser.com/posts/1143163/revisions) – Cas Nov 10 '16 at 08:02
  • @cascar1 It was your comment on edit about an unintelagle sentence that I was trying to explain. If only I had edit priviledge :-) – Brad Sturtevant Nov 11 '16 at 00:49