L3·Functions & Modules
🧪Virtual Environments & pip
Isolated dependency worlds per project.
venvpiprequirements
§ 1Why venv?
Each project gets its own site-packages so versions never collide with the system Python.
§ 2Create & activate
python -m venv .venv, then source .venv/bin/activate (or .venv\Scripts\activate on Windows).
§ 3pip
pip install X, pip freeze > requirements.txt, pip install -r requirements.txt.
Example
1# Shell — not Python:2# python -m venv .venv3# source .venv/bin/activate4# pip install requests5# pip freeze > requirements.txt6import sys7print(sys.prefix) # points at .venv when activatedTry it live · Python runs in your browser
Loading playground…
Checkpoint quiz
Question 1 / 2
What does pip freeze do?