Creating Python Virtual Environment in Windows and Linux
A Virtual Environment is a Python environment, that is an isolated working copy of Python that allows you to work on a specific project without affecting other projects So basically it is a tool that enables multiple side-by-side installations of Python, one for each project.
Creating a Python virtual environment in Linux
Step 1: Ensure Python and pip are installed
On most Linux distributions, Python 3 and pip can be installed via package manager:
sudo apt update
sudo apt install python3 python3-pip python3-ven
Step 2: Create a virtual environment
This creates a folder myenv (you can use any name) containing the isolated Python environment.
python3 -m venv myenv
Step 3: Activate the virtual environment
source myenv/bin/activate
Your shell prompt will change to indicate the active environment.
Step 4: Deactivate the virtual environment
deactivate
Creating Python Virtual Environment in Windows
If python is installed in your system, then pip comes in handy. So simple steps are:
Step 1: Create a virtual environment
Open Command Prompt or PowerShell, navigate to your project folder, and run:
python -m venv myenv
Step 2: Activate the virtual environment
myenv\Scripts\activate
Step 4: Deactivate the virtual environment
Simply run:
deactivate