Python not working in the command line of git bash Python not working in the command line of git bash python python

Python not working in the command line of git bash


Temporary solution

Just enter this in your git shell on windows - > alias python='winpty python.exe', that is all and you are going to have alias to the python executable. This alias will be valid for the duration of the shell session.

winpty is a Windows software package providing an interface similar to a Unix pty-master for communicating with Windows console programs.

Permanent solution

Add the command to your .bashrc in the users home directory.

Using CLI

This can be accomplished from git bash like so:

echo "alias python='winpty python.exe'" >> ~/.bashrc

which will create .bashrc in the current users home directory if the file doesn't exist or append the alias to the end of .bashrc if it does.

Using a text editor

Alternatively, you could first create a .bashrc. Depending on your file manager, this may be easier to accomplish in git bash like so:

cd ~touch .bashrc

At which point you can open .bashrc in your prefered text editor and add it there.

To apply the change, either use the command source .bashrc or restart the shell.


I don't see next option in a list of answers, but I can get interactive prompt with "-i" key:

$ python -iPython 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:18:55)Type "help", "copyright", "credits" or "license" for more information.>>> 


This is a known bug in MSys2, which provides the terminal used by Git Bash. You can work around it by running a Python build without ncurses support, or by using WinPTY, used as follows:

To run a Windows console program in mintty or Cygwin sshd, prepend console.exe to the command-line:

$ build/console.exe c:/Python27/python.exePython 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32Type "help", "copyright", "credits" or "license" for more information.>>> 10 + 2030>>> exit()

The prebuilt binaries for msys are likely to work with Git Bash. (Do check whether there's a newer version if significant time has passed since this answer was posted!).


As of Git for Windows 2.7.1, also try using winpty c:Python27/python.exe; WinPTY may be included out-of-the-box.