Git Bash Workaround - Run Python 2 and Python 3 with Aliases
Hi This is (for me) the best solution to run both Python (Python 2.7 and Python 3.x) directly from Git Bash on Win 10 => add aliases to the aliases file for which Git Bash uses.
The Git Bash aliases file is aliases.sh . It is in:
C:\path where you installed Git\etc\profile.d\aliases.sh
1) Open (using a text editor such as Atom or another) the aliases.sh file
for example: in my case, the file is located in C:\Software\Develop\Git\etc\profile.d\aliases.sh
2) Add your alias for Python
In my case, python.exe is installed in:
C:\Networking\Network Automation\Python 2.7\python.exe C:\Networking\Network Automation\Python 3.7\python.exe
So you have to create 2 aliases, one for Python 2 (I called python2 ) and the other for Python 3 (I just called python ). Git Bash uses the linux file structure, so you need to change "\" to "/", and if you have a path like in my Network Automation example you put it with ""
Network Automation, for example
winpty is a magic command that invokes an executable file.
So add these lines at the beginning of aliases.sh
alias python2='winpty C/Networking/"Network Automation"/"Python 2.7"/python.exe' alias python='winpty C/Networking/"Network Automation"/"Python 3.7"/python.exe'
3) Add or change other aliases (if you want)
I also changed the alias ll to show all files in a readable list:
alias ll='ls -lah'
4) Save the aliases.sh file
5) OK !!! close and restart your git bash
Now you can constantly run both Python directly from the Git shell, just by writing
$ python run Python 3
$ python2 run Python 2
$ ll β enter ls -lah to quickly show your detailed list of files
Hooray Harry
Harry May 21 '19 at 17:07 2019-05-21 17:07
source share