Now we will see how to install the virtual environment and how to activate it.
To install the virtual environment on Linux, perform the following steps:
- First check whether pip is installed or not. We are going to install pip for python3:
sudo apt install python3-pip
- Install the virtual environment using pip3:
sudo pip3 install virtualenv
- Now we will create the virtual environment. You can give it any name; I have called it pythonenv:
virtualenv pythonenv
- Activate your virtual environment:
source venv/bin/activate
- After your work is done, you can deactivate virtualenv by using following command:
deactivate
In Windows, run the pip install virtualenv command to install the virtual environment. The steps for installing virtualenv are same as with Linux.