1

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

jfs
417k211 gold badges1k silver badges1.7k bronze badges
asked Oct 21, 2014 at 21:19
5
  • 2
    What operating system do you have? Commented Oct 21, 2014 at 21:24
  • For windows 7: stackoverflow.com/questions/3809314/… Commented Oct 21, 2014 at 21:26
  • @SimeonVisser Windows 7 ultimate Commented Oct 21, 2014 at 21:27
  • For ubuntu: askubuntu.com/questions/196071/… just apt-get both versions Commented Oct 21, 2014 at 21:27
  • you haven’t provided the operating system used so as to answer your question Commented Sep 28, 2023 at 14:24

2 Answers 2

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.

answered Oct 22, 2014 at 10:12
Sign up to request clarification or add additional context in comments.

Comments

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 %*

answered Oct 22, 2014 at 7:59

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.