Dependency versions and reproducibility
Quick answer
A reproducible experiment needs more than the Python source. Record interpreter version, package versions, data identity, configuration, seed, device and any important numerical settings. A virtual environment isolates an interpreter’s installed packages from other environments; it does not install a new Python release by itself or guarantee safe execution. A dependency lock records a resolved dependency set for a specific target environment.
Describe the experiment explicitly
A manifest is a small record describing a run. The following is a fictional configuration, not a measurement of your machine. The data identifier is a version label; later experiments should also use a content checksum.
run = {"fixture": "parcel-v1", "seed": 17, "device": "cpu", "dependencies": []}print(run["fixture"])print(run["device"])print(len(run["dependencies"]))Expected output:
parcel-v1cpu0This example uses only Python’s standard library, so there are no external dependencies. Interpreter version still matters.
Read the actual interpreter version
The sys module exposes the running Python version. Instead of guessing a patch number, read the version fields from the running interpreter. The two output lines check the major version and the number of release components; they deliberately avoid installation-specific patch numbers.
import sys
version = sys.version_infoprint(version.major == 3)print(len([version.major, version.minor, version.micro]))Expected output:
True3The version has three numeric components used in a release record. This example intentionally avoids printing an environment-specific patch. On a local machine, python --version reports the exact interpreter; confirm that it is the one running the experiment.
Common mistakes
An unpinned dependency list can resolve differently tomorrow. A pinned top-level package alone may still allow different transitive dependencies. A freeze of an existing environment is useful evidence, not automatically a portable lock or a security review. Use reviewed dependencies, hashes and a target-specific lock when libraries are introduced; do not install packages from an unknown file.
Practice and next steps
Write a manifest for the chapter milestone: actual Python version, fixture ID and hash, CPU, no external packages, and whether randomness was used. In an approved local setup, python -m venv .venv can create an isolated environment; installation and activation are optional and not executed here. Record actual versions rather than claiming a latest release.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Dependency versions and reproducibility — knowledge check
Apply the lesson to small reproducible experiment scenarios.
What does a virtual environment primarily isolate?
Which version should a run record contain?
Why are top-level package pins sometimes insufficient?
What helps verify the exact data content?
What does no external dependencies mean here?