Fundamentals 5 min read

How to Switch Between Python 2 and Python 3 Virtual Environments on Windows

This guide walks you through creating and managing Python virtual environments on Windows, showing how to specify Python 2 or Python 3 with virtualenv, activate and deactivate them, and verify the interpreter version using clear step‑by‑step instructions and screenshots.

Python Crawling & Data Mining
Python Crawling & Data Mining
Python Crawling & Data Mining
How to Switch Between Python 2 and Python 3 Virtual Environments on Windows

The article explains how to create a Python virtual environment with a specific interpreter version on Windows using the virtualenv tool.

Before starting, ensure both Python 2 and Python 3 are installed on the system.

Step 1: Open a command prompt and run virtualenv -p C:\Python27\python.exe demo to create a virtual environment named demo that uses Python 2.

Step 2: After execution, the demo virtual environment is created, as shown in the screenshot.

Step 3: The environment folder appears in the current directory.

Step 4: Inside the Scripts folder you can see that the Python executable is the Python 2 version.

Step 5: Activate the environment by running activate.bat.

After activation, the command prompt shows (demo) at the beginning, indicating the virtual environment is active.

Step 6: Inside the activated environment, run python to verify that the interpreter version is Python 2.

Step 7: To exit, press Ctrl+Z or type exit() to leave Python, then run deactivate.bat.

After deactivation, the (demo) prefix disappears, confirming the environment is no longer active.

Step 8: Creating a new virtual environment without the -p option defaults to Python 3, allowing you to switch freely between Python versions as needed.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

PythonTutorialpython3Environment
Python Crawling & Data Mining
Written by

Python Crawling & Data Mining

Life's short, I code in Python. This channel shares Python web crawling, data mining, analysis, processing, visualization, automated testing, DevOps, big data, AI, cloud computing, machine learning tools, resources, news, technical articles, tutorial videos and learning materials. Join us!

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.