Dependency Resolution & Conflicts
Your project asks for a few packages; they ask for others; those ask for more. A resolver has to pick exactly one version of every package so that every requirement in the whole graph is satisfied at once. Python allows only one version of a package per environment, so when two packages need incompatible versions of a third, there is no answer, and the resolver's job becomes explaining why.
How the resolvers work
| Tool | Resolver | Strategy |
|---|---|---|
| pip (since 20.3) | resolvelib | backtracking: try the newest candidate, go back when a later requirement can't be met |
| uv | PubGrub (Rust) | conflict-driven: learns why a choice failed and never retries it; produces a derivation as its error message |
| Poetry | its own (mixology, also PubGrub-based) |
same idea; resolves for every platform and Python version in requires-python |
Before 2020, pip didn't resolve at all: it installed the first version it met and printed a warning if something broke later. Old blog posts that say "pip doesn't check conflicts" are about that era.
A real conflict
To make one, this session builds two tiny local packages: report-kit needs attrs>=26, and legacy-plugin needs attrs<25. The index has attrs 26.1.0 and 24.2.0, so each is installable alone, but not together:
python3 -m venv .venv && . .venv/bin/activate
make_pkg() { # name, dependency
mkdir -p "$1/src/${1//-/_}"
printf '[build-system]\nrequires = ["hatchling"]\nbuild-backend = "hatchling.build"\n\n[project]\nname = "%s"\nversion = "1.0.0"\nrequires-python = ">=3.13"\ndependencies = ["%s"]\n' "$1" "$2" > "$1/pyproject.toml"
touch "$1/src/${1//-/_}/__init__.py"
uv build -q --wheel -o wheels "$1"
}
make_pkg report-kit "attrs>=26"
make_pkg legacy-plugin "attrs<25"
ls wheels
echo "=== each alone"
pip install --dry-run --find-links wheels report-kit 2>&1 | grep 'Would install'
pip install --dry-run --find-links wheels legacy-plugin 2>&1 | grep 'Would install'
echo "=== together, with pip"
pip install --find-links wheels report-kit legacy-plugin 2>&1 | sed -n '/^ERROR: Cannot/,/^$/p;/conflict is caused/,/^$/p'
echo "=== together, with uv"
uv pip install --find-links wheels report-kit legacy-plugin 2>&1legacy_plugin-1.0.0-py3-none-any.whl
report_kit-1.0.0-py3-none-any.whl
=== each alone
Would install attrs-26.1.0 report-kit-1.0.0
Would install attrs-24.2.0 legacy-plugin-1.0.0
=== together, with pip
ERROR: Cannot install legacy-plugin==1.0.0 and report-kit==1.0.0 because these package versions have conflicting dependencies.
The conflict is caused by:
report-kit 1.0.0 depends on attrs>=26
legacy-plugin 1.0.0 depends on attrs<25
=== together, with uv
error: No solution found when resolving dependencies
cause: Because all versions of legacy-plugin depend on attrs<25 and all versions of report-kit depend on attrs>=26, we can conclude that all versions of legacy-plugin and all versions of report-kit are incompatible.
And because you require report-kit and legacy-plugin, we can conclude that your requirements are unsatisfiable.
Both tools find the same contradiction; they explain it differently. pip lists the clashing requirements. uv prints a derivation: a chain of "because … and because …, we can conclude …" steps from the facts to the failure. With deep graphs uv's form is much easier to follow back to the root cause.
The same conflict in a project
Project managers resolve when you add, so a conflict appears before anything is installed, and pyproject.toml is left untouched. Note that uv resolves the main dependencies and the dev group together (one lockfile, one consistent set), so a test tool can't quietly require a different attrs than the app:
uv init -q --no-package app && cd app
uv add -q "attrs>=26"
uv add --dev "attrs<25" 2>&1
echo "--- pyproject.toml is unchanged"
grep -A2 '^dependencies' pyproject.tomlerror: Failed to add dependencies
cause: No solution found when resolving dependencies
cause: Because your project depends on attrs>=26 and app:dev depends on attrs<25, we can conclude that your project and app:dev are incompatible.
And because your project requires your project and app:dev, we can conclude that your project's requirements are unsatisfiable.
hint: If you want to add the package regardless of the failed resolution, provide the `--frozen` flag to skip locking and syncing
--- pyproject.toml is unchanged
dependencies = [
"attrs>=26",
]
(Adding attrs<25 to the main dependencies wouldn't fail: uv add replaces an existing requirement for the same package rather than adding a second one.)
Fixing a conflict
In order of preference:
- Upgrade the stragglers. Usually a newer release of the package with the old upper bound (
legacy-plugin) has relaxed it.pip index versions legacy-plugin/uv tree --outdatedshow what's available. - Downgrade the other side if its newer requirement is the problem (
report-kit<…), as a temporary pin with a comment explaining why. - Override. uv lets an application overrule a dependency's metadata:
[tool.uv] override-dependencies = ["attrs>=26"]; pip has no equivalent except installing with--no-deps. You're then responsible for checking thatlegacy-pluginreally works with attrs 26. - Fork or vendor the abandoned package. Last resort.
Note: The root cause is almost always an upper bound in a library (
attrs<25). Libraries that cap their dependencies "just in case" create unsolvable graphs for everyone downstream; see the field notes.
A runnable model: a tiny backtracking resolver
This resolver does what pip's does, in miniature: walk the requirements, try the newest candidate that matches every specifier collected so far, and backtrack when a dependency can't be satisfied. It logs each decision:
index = { # package -> version -> dependencies
"app": {"1.0": {"report-kit": ">=1", "web": ">=2"}},
"report-kit": {"1.0": {"attrs": ">=24"}, "2.0": {"attrs": ">=26"}},
"web": {"2.0": {"attrs": "<25"}, "2.1": {"attrs": ">=24"}},
"attrs": {"24.2": {}, "26.1": {}},
}
def v(s): return tuple(int(x) for x in s.split("."))
def ok(version, spec):
op, num = (spec[:2], spec[2:]) if spec[:2] in (">=", "<=", "==") else (spec[:1], spec[1:])
return {">=": v(version) >= v(num), "<": v(version) < v(num), "==": v(version) == v(num)}[op]
def resolve(todo, chosen, depth=0):
if not todo:
return chosen
(name, spec, parent), rest = todo[0], todo[1:]
if name in chosen: # already picked: must still match
if ok(chosen[name], spec):
return resolve(rest, chosen, depth)
print(" " * depth + f"{name} {chosen[name]} conflicts with {parent}'s {spec}")
return None
for version in sorted(index[name], key=v, reverse=True):
if not ok(version, spec):
continue
print(" " * depth + f"try {name} {version}")
deps = [(d, s, f"{name} {version}") for d, s in index[name][version].items()]
result = resolve(rest + deps, {**chosen, name: version}, depth + 1)
if result:
return result
print(" " * depth + f"backtrack from {name} {version}")
return None
print(resolve([("app", ">=1", "user")], {}))
print("--- now web 2.1 is yanked")
del index["web"]["2.1"]
print(resolve([("app", ">=1", "user")], {}))try app 1.0
try report-kit 2.0
try web 2.1
try attrs 26.1
{'app': '1.0', 'report-kit': '2.0', 'web': '2.1', 'attrs': '26.1'}
--- now web 2.1 is yanked
try app 1.0
try report-kit 2.0
try web 2.0
try attrs 26.1
attrs 26.1 conflicts with web 2.0's <25
backtrack from attrs 26.1
backtrack from web 2.0
backtrack from report-kit 2.0
try report-kit 1.0
try web 2.0
try attrs 26.1
attrs 26.1 conflicts with web 2.0's <25
backtrack from attrs 26.1
try attrs 24.2
{'app': '1.0', 'report-kit': '1.0', 'web': '2.0', 'attrs': '24.2'}
In the second run the resolver backtracks out of report-kit 2.0 and finds a solution with the older report-kit 1.0, whose looser attrs>=24 agrees with web. That's the behaviour behind pip's "INFO: pip is looking at multiple versions of …" message, and also why resolution can get slow: with many packages and many versions, naive backtracking explores a lot of dead ends. PubGrub avoids most of them by remembering the reason for each failure.
Test yourself
Why can't Python just install both attrs 24 and attrs 26 to satisfy two packages?
- It can, with --multi-version
- An environment can hold only one version of a distribution, since
import attrsmust resolve to one module - attrs forbids it
- Only on Windows
What is backtracking in a resolver?
- Downloading packages twice
- Undoing an earlier version choice when it leads to an unsatisfiable requirement, and trying another candidate
- Installing older Python versions
- Reading the lockfile backwards
What's usually the root cause of an unsolvable graph like report-kit + legacy-plugin?
- Too many lower bounds
- A library pinning an upper bound (
attrs<25) that newer packages can't meet - Using uv
- Missing wheels