Python - Install Virtual Environment
A Python virtual environment is a tool that helps to create an isolated environment for a project.
Virtual environment is required to manage dependencies for different projects. Using virtual environment allows you to avoid installing Python dependencies globally which could break system tools or other projects. Virtual environment can be installed using pip.
Install Virtual Environment
Command to create virtual environment on Windows:
py -m pip install --user virtualenv
Command to install virtual environment on Ubuntu/Linux/macOs:
python3 -m pip install --user virtualenv
Create a Virtual Environment
Command to create a virtual environment on Windows:
py -m venv env
Command to create a virtual environment on Ubuntu/Linux/macOs:
python3 -m venv env
Activate a Virtual Environment
Command to activate virtual environment on Windows:
.\env\Scripts\activate
Command to activate virtual environment on Ubuntu/Linux/macOs:
source env/bin/activate
Deactivate the Virtual Environment
Command to deactivate virtual environment on Windows/Ubuntu/Linux/macOs:
deactivate