How to install both Python 2.x and Python 3.x in Windows How to install both Python 2.x and Python 3.x in Windows windows windows

How to install both Python 2.x and Python 3.x in Windows


I found that the formal way to do this is as follows:

Just install two (or more, using their installers) versions of Python on Windows 7 (for me work with 3.3 and 2.7).

Follow the instuctions below, changing the parameters for your needs.

Create the following environment variable (to default on double click):

Name:  PY_PYTHONValue: 3

To launch a script in a particular interpreter, add the following shebang (beginning of script):

#! python2

To execute a script using a specific interpreter, use the following prompt command:

> py -2 MyScript.py

To launch a specific interpreter:

> py -2

To launch the default interpreter (defined by the PY_PYTHON variable):

> py

Resources

Documentation: Using Python on Windows

PEP 397 - Python launcher for Windows


What I did was download both 2.7.6 and 3.3.4. Python 3.3.4 has the option to add the path to it in the environment variable so that was done. So basically I just manually added Python 2.7.6.

How to...

  1. Start > in the search type in environment select "Edit environment variables to your account"1

  2. Scroll down to Path, select path, click edit.

  3. Add C:\Python27;so you should have paths to both versions of Python there, but if you don't this you can easily edit it so that you do..... C:\Python27;C:\Python33;

  4. Navigate to the Python27 folder in C:\ and rename a copy of python.exe to python2.exe

  5. Navigate to the Python34 folder in C:\ and rename a copy of python.exe to python3.exe

  6. Test: open up commmand prompt and type python2 ....BOOM! Python 2.7.6. exit out.

  7. Test: open up commmand prompt and type python3 ....BOOM! Python 3.4.3. exit out.

Note: (so as not to break pip commands in step 4 and 5, keep copy of python.exe in the same directory as the renamed file)


I have multiple versions in windows.I just change the exe name of the version I'm not defaulting to.

python.exe --> python26.exe

pythonw.exe --> pythonw26.exe

As for package installers, most exe installers allow you to choose the python install to add the package too.For manual installation check out the --prefix option to define where the package should be installed:

http://docs.python.org/install/index.html#alternate-installation-windows-the-prefix-scheme