Using Python Virtual Environments (venv)
Dev Guides / python-venv.html
Create an isolated package space per project to avoid version clashes and global installs.
๐ฌ A virtual environment gives each project its own package room.
Installing globally causes version clashes between projects. With a venv you can install whatever version each project needs.
Create and activate
# in your project folder
python3 -m venv .venv
# activate
source .venv/bin/activate # macOS / Linux
.venv\Scripts\activate # Windows
# packages now install only into this environment
python -m pip install requests
Exit
deactivate
Common problems
- pip install permission error: you are installing globally. Check the venv is active (
which python). - Packages gone after reopening: the venv is not active. Confirm
(.venv)appears in your prompt.
Sources
- Official docs venv โ Python docs โ Official docs
- Official docs Installing Packages โ Packaging guide
Verified date indicates freshness. Check applicability conditions for older material.