Fundamentals 5 min read

How to Create a Default Virtual Environment on Windows to Separate Python2 and Python3

This guide walks you through installing virtualenv on Windows, creating a named virtual environment, locating its files, activating it with activate.bat, checking the Python version, and properly deactivating the environment to keep Python2 and Python3 projects isolated.

Python Crawling & Data Mining
Python Crawling & Data Mining
Python Crawling & Data Mining
How to Create a Default Virtual Environment on Windows to Separate Python2 and Python3

Install virtualenv

Run pip install virtualenv. If the package is already present, pip reports that it exists.

Create a virtual environment

Execute virtualenv test, where test is an arbitrary name for the environment. The command creates a directory named test in the current working directory (e.g., C:\Users\lenovo).

Directory layout

The created test folder contains a Scripts subdirectory. Inside Scripts are the activation scripts ( activate.bat) and the Python executable.

Activate the environment

Run activate.bat from the Scripts directory (or from a command prompt whose current directory is test\Scripts). The command prompt prefixes the environment name in parentheses, indicating that the virtual environment is active.

activate.bat

Verify Python version

With the environment active, run python. The interpreter reports its version; in the example it is Python 3.

python

Deactivate the environment

Exit the Python REPL with exit() (or Ctrl+Z). Then run deactivate.bat to leave the virtual environment; the prompt returns to its original form.

deactivate.bat

Notes

The default virtual environment uses the system’s Python 3 interpreter. Creating a Python 2 virtual environment is not covered in this article.

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.

PythonWindowsvirtual environmentvirtualenvpipenvironment isolation
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.