Managing Python 2 and Python 3 Coexistence on Windows

Setting Up Python 2 and Python 3 Side by Side on Windows

To work with both Python 2 and Python 3 simultaneously on a Windows system, follow these steps:

  1. Download and install Python 2.x and Python 3.x.
  2. Configure environment variables. Add the installation directories and their Scripts subdirectories to the PATH user variable, separated by semicolons.
  3. Rename python.exe to python2.exe and python3.exe in their respective installation directories. Similarly, rename pythonw.exe to pythonw2.exe and pythonw3.exe.
  4. Upgrade pip for both versions by executing the following commands in Command Prompt:
python2 -m pip install --upgrade pip --force-reinstall
python3 -m pip install --upgrade pip --force-reinstall
  1. Verify the installation by typing python2 or python3 in the command prompt to access the respective environments. Use pip2 -V and pip3 -V to check pip versions. Install packages with pip2 install package_name or pip3 install package_name.

Detailed Instructions

1. Download and Install Python 2.x and Python 3.x

  • Visit https://www.python.org/downloads/ and download the appropriate Windows installers for both versions.
  • Run the installers with default settings. Note the installation directories (e.g., D:\Python27 and D:\Python35).
  • During Python 3 installation, you may check "Add Python to PATH" to automatically configure environment variables.

2. Configure Environment Variables

  • Open System Properties > Environment Variables.
  • Edit the PATH variable to include both Python installations and their Scripts directories:
D:\Python27\Scripts;D:\Python27;
D:\Python35\Scripts;D:\Python35;

3. Rename Executable Files

  • In the Python 2 directory, rename python.exe to python2.exe and pythonw.exe to pythonw2.exe.
  • In the Python 3 directory, rename python.exe to python3.exe and pythonw.exe to pythonw3.exe.
  • Note: python.exe opens a console window, while pythonw.exe runs without a console (useful for GUI applications).
  • In scripts, specify the interpreter with #! D:\python27\python2.exe for Python 2 or #! D:\python35\python3.exe for Python 3.

4. Upgrade pip

Ensure both Python versions have their own pip installation by running the upgrade commands for each version:

python2 -m pip install --upgrade pip --force-reinstall
python3 -m pip install --upgrade pip --force-reinstall

5. Verification

Test the setup by running:

  • python2 --version and python3 --version to confirm correct versions.
  • pip2 --version and pip3 --version to check pip versions.
  • Execute scripts with python2 script.py or python3 script.py.

Tags: python Windows Python 2 Python 3 Environment Setup

Posted on Sun, 06 Sep 2026 16:25:44 +0000 by sebastienp