Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.“It works on my machine”
Your code uses libraries, those libraries use other libraries, and each comes in many versions. If you and a teammate have different versions, the same script can give different results, or not run at all. Python’s answer has three parts: a separate environment per project (its own private set of libraries), a project file listing what the project needs, and a lock file recording the exact versions that were chosen, so anyone can rebuild the identical environment.
Flight-dynamics results, trained perception models and test reports must be reproducible months later on a different computer, an HPC cluster or a CI runner. Pinned, locked environments (plus containers, C4) are what make “rerun the analysis from the paper” possible, and they are mandatory for certified ground software.
- 1. A virtual environment gives a project…
- 2. A lock file records…
- 3. Without isolation, two projects needing different versions of numpy…
Level 1: Beginner
★★☆☆☆ Basic⏱ 25 minSecondary-school mathematics: arithmetic and elementary algebra.Environments
python -m venv .venv && source .venv/bin/activate # stdlib venv
uv venv && uv pip install numpy # uv: fast Rust-based tool
conda create -n sim python=3.12 numpy scipy && conda activate simA venv is just a directory with its own bin/python (Scripts\python.exe on Windows) and site-packages. Activation puts it first on PATH.
Installing
pip install "numpy>=1.24,<3" downloads from PyPI. It prefers wheels (pre-built .whl archives, platform-tagged like cp312-manylinux_x86_64) and falls back to sdists (source, built locally, which may need compilers). conda installs binaries of anything (Python, CUDA, GDAL, compilers) from its own channels (conda-forge). Use it when non-Python libraries matter, and avoid mixing pip and conda in one environment except at the end.
Declaring a project: pyproject.toml
[project]
name = "orbitkit"
version = "0.3.1"
requires-python = ">=3.10"
dependencies = ["numpy>=1.24", "scipy~=1.11"]
[project.optional-dependencies]
viz = ["matplotlib>=3.8"]
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"- 1. A wheel is…
- 2. Where does a venv's interpreter live on Linux/macOS?
- 3. Which tool can install CUDA toolkits and compilers as packages?
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 35 minUndergraduate students and practising engineers.Version specifiers (PEP 440)
- Ordering:
1.0.dev1 < 1.0a1 < 1.0b1 < 1.0rc1 < 1.0 < 1.0.post1 < 1.1 < 1.10. Components compare as integers, so 1.10 > 1.9, and1.0 == 1.0.0. - Operators:
==, !=, <, <=, >, >=, wildcards==1.2.*, and the compatible-release operator~=1.4.2(meaning>=1.4.2, <1.5;~=2.3means>=2.3, <3). - Pre-releases are excluded unless a specifier mentions one or you pass
--pre.
Resolution is search
Each package version declares requirements, and choices interact: picking the newest X may force a Y that conflicts with Z. pip’s resolver (resolvelib) and uv’s (PubGrub) search for an assignment satisfying every constraint, backtracking on conflicts. In general this is NP-hard (it can encode SAT), but real dependency graphs are usually easy.
Locking
uv lock, poetry lock and pip-compile record the full resolved set, with hashes, so uv sync or pip install --require-hashes -r requirements.txt reproduces it exactly, and a tampered download fails the hash check.
- 1. ~=1.4.2 is equivalent to…
- 2. Does 2.0rc1 satisfy >=1.0 by default?
- 3. Which is newer: 1.10 or 1.9?
Level 3: Advanced
★★★★☆ Advanced⏱ 35 minGraduate level, with full derivations and proofs.Why resolution can be hard
Encode a SAT formula: each variable becomes a package with versions 0 and 1, and each clause becomes a package whose versions each require one literal’s choice. A consistent install exists exactly when the formula is satisfiable, so general dependency resolution is NP-complete (Di Cosmo et al., 2006). Practical resolvers rely on heuristics: newest-first, learning which conflicts to avoid (PubGrub’s incompatibility derivation, similar to CDCL SAT solvers), and pruning.
Why environments break
- Diamond dependencies: A needs C below 2 and B needs C at least 2, with no solution.
- Unpinned transitive dependencies drift over time (“it worked last month”).
- ABI mismatches: compiled extensions built against a different NumPy or CUDA.
- Mixing installers: conda and pip overwrite each other’s files.
Reproducibility ladder
Unpinned requirements.txt → pinned versions → locked with hashes → locked plus a container image (C4) → plus a fixed hardware/driver stack. Each rung removes a source of drift.
- 1. General dependency resolution is…
- 2. A diamond-dependency conflict arises when…
- 3. Hashes in a lock file protect against…
Level 4: Expert
★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.Resolution, measured
Exercise 2 (toy index: app → sim, viz → numlib). Installing “the newest of everything, in order” picks sim 2.2 (wants numlib ≥ 2.1) and viz 1.2 (wants numlib < 2.1), producing an environment with an unmet requirement. The backtracking resolver tries 8 candidates, backtracks 4 times, and returns app 1.0, sim 2.1, viz 1.2, numlib 2.0, which satisfies every constraint. Adding numlib>=2.1 makes the problem unsatisfiable; the resolver proves it after exhausting 11 candidates, which is exactly the “ResolutionImpossible” error pip prints.
In AI, robotics and aerospace
- Lock files and containers for reproducible training runs and flight-dynamics analyses.
- conda-forge / mamba for GPU stacks (CUDA, cuDNN), ROS dependencies and geospatial libraries.
- uv for fast, lockfile-based workflows in CI.
- Internal package indexes and hash pinning for supply-chain security in mission software.
References
- PEP 440 (version identification), PEP 508 (dependency specifiers), PEP 517/518/621 (pyproject.toml), PEP 427 (wheels).
- Python Packaging Authority. Python Packaging User Guide (packaging.python.org).
- Astral. uv documentation (docs.astral.sh/uv).
- R. Di Cosmo, B. Durak, X. Leroy, F. Mancinelli, J. Vouillon (2006). “Maintaining large software distributions: new challenges from the FOSS era.” FRCSS workshop.
- N. Weizenbaum (2018). “PubGrub: next-generation version solving.” (medium.com/@nex3).