QUICK START:HTMLCSSJavaScriptTypeScriptPythonSQLReactNext.jsNode.jsDSASystem DesignDevOpsCybersecurityAI / ML
Intermediate 16 min readModule: Module 11: Package Management with pip & Virtual Environments

Virtual Environments (venv), pyproject.toml & pip

Isolate project dependencies with venv, manage versions, and configure modern pyproject.toml package metadata.

What You Will Learn in This Lesson

  • Creating isolated environments with python -m venv .venv
  • Locking dependencies with pip freeze > requirements.txt
  • Modern packaging standards with pyproject.toml and hatch/poetry

Introduction & Core Concept

Python virtual environments create isolated folder environments with their own Python interpreter and site-packages, preventing dependency conflicts between projects.
WHY DOES THIS MATTER IN THE REAL WORLD?

Virtual environments guarantee that installing package updates in one project never breaks other projects on your machine.

Virtual Environment Setup Commands

bash
bash
1
2
3
4
5
6
7
8
9
# 1. Create virtual environment
python -m venv .venv
# 2. Activate environment
# Windows: .venv\Scripts\activate
# macOS/Linux: source .venv/bin/activate
# 3. Install packages
pip install fastapi uvicorn pydantic

Line-by-Line Technical Breakdown

1Modern packaging uses pyproject.toml as defined in PEP 518/621.

Try It Yourself (Interactive Editor)

Modify the code in real-time and click Run to test live browser output and console logs.

Intelligent Code Runner & Live Sandbox[BASH]
BASH SOURCE EDITOR
Interactive Live Code

Industry Best Practices & Professional Standards

  • Never install packages globally into the system Python; always use a virtual environment.

Lesson Summary & Core Takeaways

  • Virtual environments guarantee reproducible, conflict-free Python project dependencies.