How to Create a virtual environment using Python in Windows

Abhishek Nair
2 min readJan 28, 2021
Virtual Environment in Python

What’s an Virtual Environment?

A virtual environment is a Python environment such that the Python interpreter, libraries and scripts installed into it are isolated from those installed in other virtual environments, and (by default) any libraries installed in a “system” Python, i.e., one which is installed as part of your operating system.

OK, So now let’s get Started!

  • Creating a Virtual Environment
python -m venv env_name

This creates a virtual environment named “env_name” (you can name whatever you want)

  • Activating the Virtual Environment
env_name\Scripts\activate.bat
Activating the virtual environment

This activates the virtual environment “env_name”.

When the virtual environment gets activated, you’ll see the name of the environment inside brackets like in the screenshot above

  • Deactivating a virtual environment
deactivate
  • Removing the Virtual Environment
rmdir env_name /s

This removes the virtual environment. The “/s” keyword tells the command line to delete all the sub-directories inside the folder “env_name”

Hurray! We have learnt to how to create, activate and delete a virtual environment using python!😎

Happy coding!!

--

--