How do I specify which version of Python I want in Git Bash?

I have both Python 2 and Python 3 installed.
To get python to work at all in git bash, I have to do alias python=‘winpty python.exe’. If I just type python, it freezes. When I do this, it automatically runs Python 2. How do I get it to run Python 3?

1 Like

Any reason for using a python installed in windows instead of one installed in git bash?
Assuming that winpty’s argument is a file path, you’d change the path to the executable you wanted, wouldn’t you?

1 Like

How do I install it in git bash? I don’t really know what I’m doing, I don’t know why winpty works–I’ve just been trying to follow the tutorials and troubleshoot.

1 Like

Well, you can use winpty for this. It’s not that it doesn’t work. And, like mentioned you specify the path to the executable, python2 and python3 have different paths so there’s no ambiguity. Since their base names are the same you’ll need to specify the full file path. This is the same as how you start any program anywhere, not related to git bash or python.

Installing things in git bash isn’t the easiest thing ever.

I would use this:
https://www.msys2.org/
Which is a more complete environment, it has packages for git and python and a long list of other things (many other compilers and interpreters, but also things like vlc and whatever else) The packages for python3/2 would be python2 python3 python (likely no python3 package, and python is python3)

$ pacman -S python2 python  # install packages
# ... confirmation, download, install
$ python --version
blah blah 3
$ python2 --version
blah blah 2

Or maybe wsl if on windows 10

There’s also the option of running python from windows. Kind of comes down to what you’re trying to accomplish. If it’s just “running python”, then this seems like the obvious solution.


Escaping windows is more complicated than what dealing with a commandline is supposed to be, it’s an unfortunate barrier.

1 Like

So, if I specify the path, it freezes as if I just typed python. Do you know a way around that?

1 Like

I’m guessing you removed winpty.
What you would replace is the base name “python” with the full path.

1 Like

The command you are running is winpty.

You’re telling winpty about another program.

If you just say “python” then it will look in $PATH for python.
You could rearrange $PATH or the things in $PATH so that this results in python3 instead.
But you could also tell winpty the full path to the program.

1 Like

Thank you for your help!

1 Like