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.
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.batVerify Python version
With the environment active, run python. The interpreter reports its version; in the example it is Python 3.
pythonDeactivate 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.batNotes
The default virtual environment uses the system’s Python 3 interpreter. Creating a Python 2 virtual environment is not covered in this article.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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!
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
