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 .venv​
3# source .venv/bin/activate​
4# pip install requests​
5# pip freeze > requirements.txt​
6import sys​
7print(sys.prefix) # points at .venv when activated​

Try it live · Python runs in your browser

Loading playground…

Checkpoint quiz

Question 1 / 2
What does pip freeze do?