Sub topic 3
Declared versus resolved dependencies
This chapter assumes you know basic Python and pip, can use a command line, and understand the basics of training an ML model. You should also be comfortable with Git.
Two meanings of “the dependencies”
A dependency is a software package that your project needs. A declared dependency is a package requirement written by a developer. A resolved dependency is the exact package version selected after considering every requirement.
For example, a project might declare:
numpy>=1.24,<2
scikit-learn>=1.3,<2These declarations describe acceptable versions. They do not identify one exact environment. scikit-learn also requires other packages, such as joblib, scipy, and threadpoolctl. Those are transitive dependencies, meaning they are needed indirectly.
| Dependency set | Example | Main purpose |
|---|---|---|
| Declared | `numpy>=1.24,<2` | Describe what the project accepts |
| Resolved | `numpy==1.26.4` | Record one selected version |
| Transitive | `joblib==1.3.2` | Support another package |
A new installation can resolve a different set when a package releases a new compatible version. Even if your source code has not changed, that change can alter numerical results, model behavior, or available APIs.
Why resolution can differ
Resolvers examine the complete dependency graph. They must find versions whose requirements do not conflict.
Suppose your project requires package-a>=2, while another dependency requires package-a<2. No single version satisfies both constraints. The installer must report a conflict or use a different compatible version of the parent package.
Resolution can also depend on the Python version and platform. A package may select different wheels, which are prebuilt distribution files, on Linux, macOS, Windows, or different CPU architectures.
Generate a resolved set
Keep direct requirements in a small input file:
# requirements.in
numpy>=1.24,<2
scikit-learn>=1.3,<2Use pip-tools to resolve the full tree:
python -m pip install pip-tools
pip-compile requirements.in --output-file requirements.lock
python -m pip install --requirement requirements.lockThe generated requirements.lock lists direct and transitive packages with exact versions. Commit it to Git. A second machine can install the same selected versions instead of resolving the graph again.
With uv, the project declaration normally lives in pyproject.toml:
uv lock
uv sync --lockedThe --locked option makes the command fail if the lock file does not match the project declaration. This catches accidental edits and stale resolution data.
Exercise
Why can installing scikit-learn>=1.3 today produce a different environment from installing it six months later?
Show answer
The resolver may select newer compatible versions of scikit-learn or its transitive dependencies. An exact lock file prevents that new resolution.