If I do it in CMD, it works without issues, but if I try it in Git Bash it doesn\'t work. I like to use Git Bash as my only console, but I can\'t do that if it doesn\'t work wit
Thanks for @darthfett 's answer, which largely solves the problem!
Just FYI: Same symptom also exists when your script is using import getpass; getpass.getpass()
, and in this case python -i your_script.py
will NOT fix it, but winpty python your_script.py
still works like a charm. (Lucky that they at least provide Winpty out of box with recent versions of Git For Windows.)
So, to setup once (per virtual environment) and forget it, you can append this line at the end of your env/Script/activate
:
alias python='winpty python.exe'
It will work in that bash console. (However, if you happen to be a vim user, it still won't work inside a vim when you do :python my_script.py
in vim.)
When installing git for windows, choose to use windows default console window as shown in the picture below. This option allows you to use interactive python or nodejs. Also getpass works on this console.
enter image description here
The MinTTY terminal that is the new default terminal for Git simply doesn't support Windows console programs. I don't know why the decision was made to change the default terminal, but I know a few ways to work around this:
Bash Alias (put in your .bashrc):
alias python=winpty py.exe
Note: As of Git for Windows 2.7.1, Winpty is included out of the box. winpty can be found installed at Git\usr\bin
.
Bash Alias (put in your .bashrc):
function maybe_py() {
if [ $# -eq 0 ]; then
/c/Windows/py.exe -i
else
/c/Windows/py.exe $@
fi
}
alias python=maybe_py
Note that this may not work correctly using arrow keys to browse command history:
py -i
Or for scripts:
py script.py
What Is py.exe?
In case you are wondering why I'm referencing C:\Windows\py.exe
instead of a particular python.exe
installation, I wanted to explain a few benefits of using it (the Python Launcher for Windows:
For changing your preferred/system installation (e.g. for interactive mode), see this answer.
You need to explicit python interactive mode: python -i
You can define an alias in your .bashrc: alias python='python -i', but doing this, you will not be able to run a script file (i.e.: python script.py).
Found here: Using Windows Python from Cygwin
When installing git for windows, choose to use windows default console window as shown in the picture. This option allows you to use interactive python or nodejs. Also getpass works on this console.
You can configure the git bash console by editing the file in your "$HOME/.bashrc"
Add this line to your $HOME/.bashrc
export PATH=$PATH;c:/python34