pip ResolutionImpossible: conflicting dependencies

Since pip 20.3 the installer refuses to create a set of packages that cannot logically work together. The error looks dramatic; the useful part is a short list of claims that cannot all be true.

How to read the error

ERROR: Cannot install foo==1.2.0 and bar==3.0.0 because these package versions
have conflicting dependencies.

The conflict is caused by:
    The user requested foo==1.2.0
    foo 1.2.0 depends on django>=4.2
    The user requested bar==3.0.0
    bar 3.0.0 depends on django<4.0

ERROR: ResolutionImpossible: for help visit https://pip.pypa.io/en/latest/topics/dependency-resolution/

In that example foo and bar cannot share a django. Either bar needs a release that supports Django 4.2, or foo needs to be pinned to a release that still accepts Django 3, or one of the two apps does not belong in this environment.

Sometimes the same package appears twice with two pins you typed yourself (a loose line in requirements.txt and a tighter one in constraints.txt, or a leftover package== from an earlier experiment). The “user requested” lines are yours; the “depends on” lines come from published metadata.

A working order of attack

  1. Read every bullet before changing anything. The last one is not more important than the first.
  2. Start clean if you have been pip-installing into the same environment for months: python -m venv .venv, activate it, then install from the requirements file only. Already-installed packages become extra constraints.
  3. Relax the tightest pin that the conflict names, or upgrade the project that still depends on an abandoned range.
  4. Preview without installing (pip 22.2+): python -m pip install -r requirements.txt --dry-run.
  5. Put shared upper bounds in a constraints file rather than repeating them: pip install -r requirements.txt -c constraints.txt.

What not to do

If the error instead says a package (or extra) simply is not on the index for your Python, you want Could not find a version / No matching distribution found. Node’s cousin of this message is npm ERESOLVE.

Related

Could not find a version · metadata-generation-failed · Failed building wheel · venv not activating · ModuleNotFoundError · npm ERESOLVE

Questions

What does ResolutionImpossible mean in pip?

The dependency resolver could not find any set of package versions that satisfies every requirement at once. The “The conflict is caused by” list shows the claims that cannot all be true.

Where is the real information in a ResolutionImpossible error?

In the bullet list under “The conflict is caused by”. Lines starting “The user requested” are your pins; “depends on” lines come from each package’s published metadata.

Will pip install --legacy-resolver fix it?

It may pick a combination and exit zero, but that combination can be unloadable. Treat the flag as a diagnostic comparison, not a fix.

Does a fresh virtual environment help?

Yes, when leftover packages from earlier installs are adding hidden constraints. Create a new venv and install only from your requirements file.

How can I see what pip would install without changing anything?

python -m pip install -r requirements.txt --dry-run (pip 22.2 and later) prints the planned set or the same conflict, without installing.

Is ResolutionImpossible the same as No matching distribution found?

No. That error means a name, version or wheel tag is missing from the index. ResolutionImpossible means the files exist but their declared dependencies cannot be satisfied together.

Published .

Try it

Related guides

Newest guides