pypa/pip · error · CommandError
Cannot use '--only-dependencies' in combination with {confli
Error message
Cannot use '--only-dependencies' in combination with {conflict_message}. If this is unexpected, please refer to the user guide:
https://pip.pypa.io/en/stable/user_guide/#installing-only-dependencies What it means
Raised by check_only_deps_option_does_not_conflict() in cmdoptions.py:91 when --only-dependencies is combined with one or more incompatible options: --no-deps, --use-deprecated legacy-resolver, --requirement (-r), --requirements-from-script, or --group. The error message lists all conflicting options and links to the user guide for the --only-dependencies feature.
Source
Thrown at src/pip/_internal/cli/cmdoptions.py:91
"""
if not options.only_dependencies:
return
conflicts = []
if options.ignore_dependencies:
conflicts.append("'--no-deps'")
if "legacy-resolver" in options.deprecated_features_enabled:
conflicts.append("'--use-deprecated legacy-resolver'")
if options.requirements:
conflicts.append("'--requirement'")
if options.requirements_from_scripts:
conflicts.append("'--requirements-from-script'")
if options.dependency_groups:
conflicts.append("'--group'")
if conflicts:
if len(conflicts) > 1:
conflicts[-1] = "or " + conflicts[-1]
conflict_message = ", ".join(conflicts)
raise CommandError(
f"Cannot use '--only-dependencies' in combination with {conflict_message}. "
"If this is unexpected, please refer to the user guide:\n"
"\n"
" https://pip.pypa.io/en/stable/user_guide/#installing-only-dependencies"
)
def check_dist_restriction(options: Values, check_target: bool = False) -> None:
"""Function for determining if custom platform options are allowed.
:param options: The OptionParser options.
:param check_target: Whether or not to check if --target is being used.
"""
dist_restriction_set = any(
[
options.python_version,
options.platforms,
options.abis,View on GitHub (pinned to d7d0d0a394)
Solutions
- Remove the conflicting option identified in the error message.
- If you want deps from a requirements file without --only-deps, just use `pip install -r requirements.txt`.
- If you want a group's dependencies, use `pip install --group dev` without --only-deps.
- Switch from the legacy resolver to the default (resolvelib) resolver.
Example fix
# before pip install --only-deps --no-deps mypackage # after pip install --only-deps mypackage # (remove --no-deps; --only-deps already handles dependency-only install)
Defensive patterns
Strategy: validation
Validate before calling
def validate_only_deps_options(options):
"""Validate --only-deps doesn't conflict with incompatible options."""
if not options.get('only_dependencies'):
return True
conflicts = ['no-deps', 'legacy-resolver', 'requirement', 'requirements-from-script', 'group']
for c in conflicts:
if options.get(c):
return False
return True Try / catch
from pip._internal.exceptions import CommandError
try:
# pip install invocation
except CommandError as e:
if "'--only-dependencies'" in str(e):
# remove conflicting option and retry
Prevention
- Review the --only-deps documentation before combining with other flags.
- Test option combinations with --dry-run first.
- Keep install scripts simple; avoid stacking unrelated flags.
When it happens
Trigger: Calling `pip install --only-deps --no-deps <pkg>`, `pip install --only-deps -r requirements.txt`, `pip install --only-deps --group dev`, `pip install --only-deps --requirements-from-script script.py`, or `pip install --only-deps --use-deprecated legacy-resolver <pkg>`.
Common situations: Trying to install only dependencies of a requirements file but also passing --no-deps (logical contradiction). Mixing --group with --only-deps thinking it will install the group's deps. Using the legacy resolver with --only-deps (unsupported combination). Misunderstanding what --only-deps does (it installs the transitive dependencies of named requirements, excluding the requirements themselves).
Related errors
- When restricting platform and interpreter constraints using
- Can not use any platform or abi specific options unless inst
- Platform and interpreter constraints using --python-version,
- --build-constraint cannot be used with --no-build-isolation.
- --pre cannot be used with --all-releases or --only-final.
AI-assisted analysis of pypa/pip@d7d0d0a394 (2026-08-04).
Data as JSON: /data/errors/eebe45060caf760f.json.
Report an issue: GitHub.