pip hangs "Collecting" then resolves nothing: dependency backtracking and how to break it
Problem
Adding one package to a Docker build:
INFO: pip is looking at multiple versions of pydantic to determine the compatible version
INFO: This is taking longer than the few seconds that pip promises....followed by ten minutes of silence, a download storm, and eventually either success with a bizarre old version or:
ERROR: Cannot install -r requirements.txt (line 12) and pydantic==2.9 because these dependency versions have conflicting dependencies.Root cause
pip's resolver is a backtracking search. When your pins force it into a dead end, it walks the entire version history of each conflicting package — thousands of versions, each a metadata download. Two patterns guarantee it:
1. Partially pinned requirements: some packages pinned to exact versions, others floating (>=). Each unpinned range multiplies the search space. 2. A version that does not exist on your Python: you are on Python 3.9 and every recent release of the new package requires 3.10+. The resolver discards them one by one, newest to oldest, forever.
🔒 the fix — including 4 code blocks — is members-only. $1/mo unlocks everything.