Why can’t I run Python in Git Bash on Windows?

If you are using Git as version control system on Windows (and you should definitely use a version control system), you might also be using Git Bash. At least I do sometimes as I’m used to Linux.

A problem I found immediately, was that when you enter python to start the interactive prompt, it was hanging. I didn’t get the >>> prompt:

granat@windows MINGW64 ~
$ python

Ctrl-C helped, and by using the interactive flag (-i), I could go on:

granat@windows MINGW64 ~
$ python -i
Python 3.7.6 (tags/v3.7.6:43364a7ae0, Dec 19 2019, 00:42:30) [MSC v.1916 64 bit (AMD64)] on win32
Type “help”, “copyright”, “credits” or “license” for more information.

To fix this you can edit (or add if it doesn’t exist) the .bash_profile file in your home directory (~/.bash_profile) and add aliases to use winpty to call python:

alias python="winpty python"
alias pip="winpty pip"

Restart the Git Bash shell and now you can start interactive Python by just enter python.

Comments are closed.