How to create Python virtual environment
Step-by-step guide to creating and using Python virtual environments with venv for isolated package management.
Creating a virtual environment
- From project directory run the below command to create
virualenv:
python3 -m venv env
- Activate the
virtualenvusing:
source env/bin/activate
- Confirm if the virtual environment is active:
which python
- To leave virtual environment:
deactivate
Installing a Package
Example:
python3 -m pip install requests
For more info: Installing packages using pip and virtual environments