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
-
2What operating system do you have?Simeon Visser– Simeon Visser2014年10月21日 21:24:01 +00:00Commented Oct 21, 2014 at 21:24
-
For windows 7: stackoverflow.com/questions/3809314/…jgritty– jgritty2014年10月21日 21:26:29 +00:00Commented Oct 21, 2014 at 21:26
-
@SimeonVisser Windows 7 ultimateNicholaus Mwakatobe– Nicholaus Mwakatobe2014年10月21日 21:27:45 +00:00Commented Oct 21, 2014 at 21:27
-
For ubuntu: askubuntu.com/questions/196071/… just apt-get both versionsjgritty– jgritty2014年10月21日 21:27:52 +00:00Commented Oct 21, 2014 at 21:27
-
you haven’t provided the operating system used so as to answer your questionNicholaus Mwakatobe– Nicholaus Mwakatobe2023年09月28日 14:24:11 +00:00Commented Sep 28, 2023 at 14:24
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.
Comments
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 %*