Skip to the workspace
Pebellslearn by building
Frameworks & Tooling  ›  Lesson

Package Managers

Package Managers 19 minA package manager installs and manages reusable software packages and their dependencies according to declared requirements.

A package manager installs and manages reusable software packages and their dependencies according to declared requirements.

Compare constraints, exact pins and reproducible environments, and identify which part of that workflow a tool handles.

Installing the same direct dependency can select a different transitive dependency next month. Before choosing a package manager, distinguish what versions you permit from what versions and artifacts you resolved. The browser exercises inspect a small requirement grammar; local tools manage the complete installation.

pip writes the exact version it picked into requirements.txt; a crate labelled requests pinned at 2.31 flows into the requirements.txt list and then into pip install -r, while an unpinned numpy crate, greyed out, warns that the next install grabs whatever is newest

Pin a dependency before a release

Imagine a library release changes an API your script uses. A teammate installs a newer compatible-looking candidate, and the script now fails. This is a hypothetical upgrade scenario, not a claim about a particular requests release. The fix isn't "don't upgrade" — it's writing down which version you tested against:

pip install requests==2.31.0        # exact version — the strongest pin
pip install "requests>=2.31,<3"     # a range — allow bugfixes, block a major bump
pip freeze > requirements.txt       # write down EVERY installed package, pinned exactly
pip install -r requirements.txt     # anyone, anywhere, gets the same environment

pip freeze pins everything, including packages you never installed directly (they came in as some other package's dependency). That's good for reproducing a working environment, noisy for reading by hand — which is why requirements.txt in a real project is often hand-edited with just the direct dependencies, each with a specifier:

requests>=2.31
flask==2.0.1
django~=4.2

~=4.2 means "4.2 or newer, but not 5.0" — compatible-release pinning. A bare requests with no specifier is valid too; pip chooses a compatible candidate under the resolver's full constraints, the exact risk pinning exists to avoid.

(venv creates the isolated folder a project's packages live in — covered in full in section-15. This lesson is about what goes into that folder, not the folder itself.)

Preparing this topic’s interactive investigation…

Read someone else's requirements.txt

Reading a specifier by eye is a skill: requests>=2.31 is a name (requests), an operator (>=), and a version (2.31). Splitting it apart is ordinary string work, and it's the one part of this topic that runs anywhere:

python

The operator list is checked longest first — >= before > — because > is a substring of >=. Check > first and requests>=2.31 would split on the wrong character and leave a stray = stuck to the version.

What does this print?
def parse_requirement(spec):
    for op in (">", "=="):
        if op in spec:
            name, version = spec.split(op, 1)
            return [name.strip(), op, version.strip()]
    return [spec, None, None]

print(parse_requirement("requests>=2.31"))

Separate a dependency constraint from a reproducible installation

reader>=2 is a constraint: many versions may satisfy it. reader==2.4.1 is an exact version pin. A lock file records a resolved dependency set and, depending on the tool, artifact hashes and platform conditions. These solve related but different problems.

pip freeze reports installed distributions in requirements format. It does not solve dependencies again, explain why each package is present, or prove that the same native artifacts exist on another operating system. Keep direct requirements readable and record the resolved environment separately. Inspect upgrades as diffs rather than editing generated pins by hand without resolving again.

Work a concrete change: your application directly requires A>=1,<2, and A depends on B. A fresh install can change B even when your source code and direct requirement are unchanged. Pinning only A may still leave that difference. A complete lock narrows it, but the interpreter version, platform and external libraries remain part of the environment contract.

Choose a tool by the workflow you need: installation into an existing environment, project locking and syncing, Python interpreter management, or non-Python package management. Avoid equating all managers with the same command syntax or promising a speedup without measuring your project. Current pip has an experimental pip lock command; its documented guarantees are scoped, so “pip has no locking feature” is no longer an accurate blanket statement.

Transfer: classify A, A>=2, A==2.1, and a lock entry containing an artifact hash. State what each permits to vary. The existing exercise named has_pin retains its identity, but checks whether a version constraint exists; >2 is not an exact pin. The parser exercises intentionally handle a small grammar, not extras, environment markers, URLs and every valid requirements-file directive.

References: pip freeze, pip lock, and version specifiers.

Choose a tool for a new project

venv is in the standard library; pip is a separate installer commonly bootstrapped with Python. Together they support a widely used local workflow. Newer tools wrap the same ideas with a lockfile and a faster resolver:

Tool What it adds over pip + venv
pip installs packages and resolves dependencies; also has an experimental lock command
uv a project manager and installer with its own command surface, environment management and locking
Poetry one pyproject.toml for dependencies and packaging, plus a committed lockfile
pdm similar to Poetry, using standard project metadata and dependency locking
Conda manages non-Python dependencies too (C libraries, compilers) — common in data science, where a pure-PyPI wheel isn't enough

None of them change what a version specifier means — >=2.31 still means the same thing to uv as it does to pip. They differ in how fast they resolve a tangle of specifiers into one consistent set, and how much they manage beyond Python packages.

quick drill

A project's build needs a specific version of a C compiler, not just Python packages. Which tool is built for that?

Quick practice

What does this print?
def has_pin(spec):
    return "=" in spec

print(has_pin("requests>=2.31"), has_pin("flask>3"), has_pin("numpy==1.26.0"))
broken — fix it

It should count every spec that has an operator at all, including bare > and <. It prints 2; it should print 3.

What does this print?
specs = ["requests>=2.31", "flask", "numpy==1.26.0"]
pinned = [s for s in specs if "=" in s]
print(len(specs) - len(pinned))
What does this print?
def parse_requirement(spec):
    spec = spec.strip()
    for op in ("==", ">=", "<=", "~=", "!=", ">", "<"):
        if op in spec:
            name, version = spec.split(op, 1)
            return [name.strip(), op, version.strip()]
    return [spec, None, None]

print(parse_requirement("pytest!=7.0"))

🎯 Your turn

Write parse_requirement(spec). Given a requirement string, split it into [name, operator, version]. Try each operator in ("==", ">=", "<=", "~=", "!=", ">", "<") in that order — longest match first matters, since >= contains >. If none of them appear in spec, the requirement has no pin: return [spec, None, None].

  • parse_requirement("requests>=2.31") → ["requests", ">=", "2.31"]
  • parse_requirement("numpy") → ["numpy", None, None]

Hint: loop the operators tuple, and the moment one is found with op in spec, do spec.split(op, 1) and return the stripped pieces.

Press ▶ Run, try the Live App chips, then ✓ Check. After that, the practice set below builds a small requirements.txt reader out of this one function.

Your task
Write parse_requirement(spec). Split a requirement string into [name, operator, version] by checking each operator in ("==", ">=", "<=", "~=", "!=", ">", "<") in that order (longest match first, since >= contains >). If none appear, return [spec, None, None]. Example: parse_requirement("requests>=2.31") -> ["requests", ">=", "2.31"].

Practice — level up

0/5 solved

Solve each in its own editor — Run to try, Check to grade. Stuck? Reveal a Hint, or the full Solution + walkthrough.

Warm-upJust the package name

Write package_name(spec) that returns only the package name from a requirement string, ignoring any extras in brackets and any version operator. package_name("requests[socks]>=2.31") -> "requests".

pip
DrillHas a version constraint

Write has_pin(spec) returning True if the spec has any supported version operator. The historical function name is retained: this checks for a constraint, not necessarily an exact pin. For example, "flask>3" is constrained, while only an exact requirement such as "flask==3.1.0" pins one version.

pinning
BuildRead a whole requirements.txt

Write parse_requirements_block(text). text is a multi-line requirements.txt. Return a dict of {package_name: full_line}, skipping blank lines and lines starting with #.

requirements-txt
BossDoes this version satisfy a minimum?

Write meets_minimum(version, minimum). Both are dotted version strings like "2.31.0". Return True if version is greater than or equal to minimum, comparing numerically — "2.9" must count as LESS than "2.10", not greater.

version-specifier
CapstonePick the newest version that satisfies a minimum

Write choose_latest(versions, minimum). versions is a list of dotted version strings available for a package. Return the highest one that meets minimum (using the same numeric comparison as meets_minimum). Return None if nothing qualifies.

dependency-resolution
Project context and further resources
parse_requirement.py
Call the function you wrote — just like your app's frontend would. Edit the inputs and hit Call.
parse_requirement(spec) → listSplit a requirement string into [name, operator, version], or [name, None, None] if unpinned.
try:
returned
No app map for this section yet.
Press Run to execute your code.
Press Check to run the tests for this lesson.
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.