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
bashbash
123456789# 1. Create virtual environmentpython -m venv .venv# 2. Activate environment# Windows: .venv\Scripts\activate# macOS/Linux: source .venv/bin/activate# 3. Install packagespip 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 CodeIndustry 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.