Search code examples
pythonwindowscommand-linecmd

How to switch between python 2.7 to python 3 from command line?


I'm trying to find the best way to switch between the two python compilers, 2.7 to 3.3. I ran the python script from the cmd like this:

python ex1.py

Where do I set the "python" environment in the window's environment variable to point to either python 3.3 or 2.7?

I am wondering if there is an easy way to switch between the two versions from the cmd line?


Solution

  • For Windows 7, I just rename the python.exe from the Python 3 folder to python3.exe and add the path into the environment variables. Using that, I can execute python test_script.py and the script runs with Python 2.7 and when I do python3 test_script.py, it runs the script in Python 3.

    To add Python 3 to the environment variables, follow these steps -

    1. Right Click on My Computer and go to Properties.
    2. Go to Advanced System Settings.
    3. Click on Environment Variables and edit PATH and add the path to your Python 3 installation directory.

    For example,

    enter image description here