venv
in PythonA virtual environment is an isolated workspace for your Python projects.
It lets you install and manage packages without affecting your system-wide Python installation — perfect for avoiding dependency conflicts.
From your project folder, run:
python -m venv venv
Here:
python
is your Python interpreter-m venv
tells Python to use the built-in virtual environment modulevenv
is the folder name where the environment will be stored (you can call it anything)Windows:
venv\Scripts\activate
macOS/Linux:
source venv/bin/activate
You’ll notice (venv)
appears in your terminal prompt — meaning it’s active.
venv
Once activated, you can install packages just for this project:
pip install requests
These will be stored inside the venv
folder, not globally.
To exit:
deactivate
If someone shares a project with a requirements.txt
file:
python -m venv venv
source venv/bin/activate # or venv\Scripts\activate on Windows
pip install -r requirements.txt
Tip: Always add venv/
to your .gitignore
file so it’s not uploaded to version control.