How do I set permanent paths for both Python 2 and 3 in command prompt such that I can invoke either every time I open the command window ie 'python2' for python 2 interpreter or 'python3' for python 3 interpreter
Asked
Active
Viewed 406 times
1
-
2What operating system do you have? – Simeon Visser Oct 21 '14 at 21:24
-
For windows 7: http://stackoverflow.com/questions/3809314/how-to-install-both-python-2-x-and-python-3-x-in-windows-7 – jgritty Oct 21 '14 at 21:26
-
@SimeonVisser Windows 7 ultimate – user3731606 Oct 21 '14 at 21:27
-
For ubuntu: http://askubuntu.com/questions/196071/need-to-have-2-versions-of-python just apt-get both versions – jgritty Oct 21 '14 at 21:27
2 Answers
2
Just use python launcher: py -2
runs Python 2 and py -3
runs Python 3.
If you add #! python3
(shebang) at the top of your script then py your_script.py
will use Python 3, if you add #! python2
then it will use Python 2 automatically.
You can also configure it to run all *.py files by default.

jfs
- 399,953
- 195
- 994
- 1,670
0
Create a python2.bat and a python3.bat file somewhere on your path (could in your main python folder). That file only contains the location of the relavant python.exe, e.g.
C:\Programs\Python26\python.exe %*

Gerard
- 124
- 1
- 4