pypa/pip · error · InstallationError
Could not satisfy constraints for
Error message
Could not satisfy constraints for '{install_req.name}': installation from path or url cannot be constrained to a version What it means
In the legacy resolver (resolver.py:281-289), when an existing requirement is a constraint and the new install_req is a link (path/url) whose path differs from the constraint's link, pip raises InstallationError. A path/url install cannot be constrained to a specific version because the version is whatever that path contains.
Solutions
- Do not version-constrain path/url installs; let the path define the version.
- Make the constraint point to the same path as the install requirement.
- Move the version pin out of the constraints file for path-installed packages.
Example fix
# before # constraints.txt: pkg==1.0 pip install -c constraints.txt ./local/pkg # after pip install ./local/pkg # no version constraint on a path install
Defensive patterns
Strategy: validation
Validate before calling
# Warn if a constraints file pins a version for a path/url requirement.
import re, os
reqs = [l.strip() for l in open("requirements.txt") if l.strip() and not l.startswith("-")]
cons = [l.strip() for l in open("constraints.txt") if l.strip()]
path_req_names = {
re.match(r"([A-Za-z0-9_.-]+)", l).group(1).lower()
for l in reqs
if ("/" in l or os.sep in l or l.startswith(("git+", "http", "./", "..")))
}
for c in cons:
nm = re.match(r"([A-Za-z0-9_.-]+)", c)
if nm and nm.group(1).lower() in path_req_names and "==" in c:
print(f"Avoid version-constraining path install: {c}") Prevention
- Keep version constraints and path/url installs separate.
- Don't put version specifiers on -e or local-path requirements.
- Document which packages are path-installed so constraints authors know.
When it happens
Trigger: Using -c constraints.txt where a package is constrained by version, while simultaneously installing that package from a local path or URL with a different path.
Common situations: Mixing version constraints (-c) with editable/VCS/path installs of the same package; constraints referencing a different source than the install.
Related errors
- Constraints cannot have extras
- Could not open file
- [dependency-groups] resolution failed for
- Double requirement given
- Editable requirements are not allowed as constraints
AI-assisted analysis of pypa/pip@f399c37189 (2026-08-08).
Data as JSON: /api/errors/39dd1d953f0ff866.
Report an issue: GitHub.
Appendix: source
Thrown at src/pip/_internal/resolution/legacy/resolver.py:285
)
# When no existing requirement exists, add the requirement as a
# dependency and it will be scanned again after.
if not existing_req:
requirement_set.add_named_requirement(install_req)
# We'd want to rescan this requirement later
return [install_req], install_req
# Assume there's no need to scan, and that we've already
# encountered this for scanning.
if install_req.constraint or not existing_req.constraint:
return [], existing_req
does_not_satisfy_constraint = install_req.link and not (
existing_req.link and install_req.link.path == existing_req.link.path
)
if does_not_satisfy_constraint:
raise InstallationError(
f"Could not satisfy constraints for '{install_req.name}': "
"installation from path or url cannot be "
"constrained to a version"
)
# If we're now installing a constraint, mark the existing
# object for real installation.
existing_req.constraint = False
# If we're now installing a user supplied requirement,
# mark the existing object as such.
if install_req.user_supplied:
existing_req.user_supplied = True
existing_req.extras = tuple(
sorted(set(existing_req.extras) | set(install_req.extras))
)
logger.debug(
"Setting %s extras to: %s",
existing_req,
existing_req.extras,View on GitHub (pinned to f399c37189)