15. Virtual Environments & Dependency Management
Essential for professional development: `venv`, `source .venv/bin/activate`, `pip install`, `pip freeze > requirements.txt`, `pip install -r`, and modern `pyproject.toml` setup.
🎓 Junior Python Curriculum — Select Module
15. Virtual Environments & Dependency Management Reference
1️⃣ Virtual Environment OS Activation Matrix
| Operating System | Shell | Activation Command |
|---|---|---|
| Linux / macOS | bash / zsh | source .venv/bin/activate |
| Windows | Command Prompt (cmd) | .venv\Scripts\activate.bat |
| Windows | PowerShell | .venv\Scripts\Activate.ps1 |
| Any OS | Active shell session | deactivate |
2️⃣ Essential `pip` Package Commands
pip install <pkg>: Downloads and installs a package from PyPI.pip install <pkg>==1.2.3: Installs an exact version.pip uninstall <pkg>: Removes an installed package.pip list: Displays all installed packages in active environment.pip freeze > requirements.txt: Saves exact package versions to a text file.pip install -r requirements.txt: Installs all listed requirements.
3️⃣ requirements.txt vs Modern `pyproject.toml`
While requirements.txt is standard for locking application deployment dependencies, modern Python projects use pyproject.toml (PEP 621) to specify project metadata, build systems (hatchling, setuptools, poetry), and dependencies in a unified file.
[project]
name = "my_teach_cloud_app"
version = "1.0.0"
dependencies = [
"flask>=3.0.0",
"pytest>=8.0.0"
]