Python Tutorial 0/52 lessons ~6 min read Lesson 32

    pip & Dependency Management

    pip installs from PyPI.

    Course progress0%
    Focus
    9 guided sections
    Practice signal
    Examples included
    Career prep
    Foundation builder

    Introduction

    pip installs from PyPI. Modern projects pin deps in pyproject.toml or use a lockfile for reproducibility.

    Understanding the topic

    Core concepts to understand:

    • pip install pkg from PyPI.
    • pip freeze > requirements.txt.
    • pip install -r requirements.txt.
    • Lockfile = exact versions + transitive deps.

    Syntax reference

    Visual flow / code:

    bash
    # Install
    pip install requests==2.31.0
    pip install -r requirements.txt
    # Freeze current env
    pip freeze > requirements.txt
    # Compile a lockfile (pip-tools)
    pip-compile pyproject.toml
    # uv: super-fast install
    uv pip install -r requirements.txt

    Execution workflow

    1pip & Dependency Management Workflow
    1 / 4

    Step 1

    pip install pkg from PyPI.

    Apply this step while implementing pip & dependency management in real code.

    Real-world use

    Use lockfiles (poetry.lock, uv.lock, requirements.lock) for reproducible builds. pip freeze alone is fragile.

    Best practices

    • Pin major versions in deps.
    • Use lockfile for prod.
    • Audit with pip-audit.

    Common mistakes

    • Installing unpinned packages — breaks at the worst time.

    Hands-on exercise

    Interview preparation — practice these questions:

    • pip vs pipx?
    • requirements.txt vs lockfile?
    • What's a transitive dependency?

    Summary

    In summary: Pin + lock = reproducible. Modern tools (uv/poetry) are faster + safer.

    Ready to mark this lesson complete?Track your journey across the entire course.