Python has an inbuild venv module to create a lightweight virtual environment, it will help us to isolate and run multiple projects with different dependency. virtual environment is created on top of an existing python installed in the system.
Python virtual environment is kind of similar to docker but both are different. Docker is used to create isolated environment with different OS version and type, System dependency, different python and node version. VENV is used to created environment for python packages.
Suppose if we want to run a django and flask project instead of installing both packages globally, seprate virtual environment can be used to run the project. In future if we want to create a new project without affecting the existing project this comes handy.
Syntax
python -m venv [venv]
you can have any name as you want inside the square bracket []
Steps:
- Go to the folder where you want to create the new virtual environment.
- Run this command
python -m venv venv
To activate virtual environment in Linux or Mac use this command
source venv/bin/activate
To activate virtual environment in Windows use this command
.\venv\Scripts\activate
Learn more about python tutorials
Explore Other Related Articles
Read and Write JSON in Python Requests from API
Read and Write Python Json
How to combine two dictionaries in python using different methods
How to check if a key exists in a dictionary python
Python try exception tutorial
Python classes and objects tutorial
Top comments (0)