pypa/pip · error · CommandError
Cannot use '--only-dependencies' in combination with
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 as CommandError by check_only_deps_option_does_not_conflict (cmdoptions.py:91) when --only-dependencies is combined with mutually exclusive options. The function (lines 68-96) collects conflicts from --no-deps, --use-deprecated legacy-resolver, -r/--requirement, --requirements-from-script, and --group, joining them into a human-readable message and pointing at the user guide. --only-dependencies installs only the transitive dependencies of the requested packages, which is semantically incompatible with options that change the dependency set or supply the requirements directly.
Solutions
- Drop the conflicting option. To install only dependencies from a requirements file, copy/extract the dependency lines instead of using -r with --only-dependencies.
- If you want no dependencies at all, use --no-deps by itself (not --only-dependencies).
- If you want the package plus its deps, omit --only-dependencies entirely.
Example fix
# before pip install --only-dependencies --no-deps mypkg # after (pick one intent) pip install --only-dependencies mypkg # or pip install --no-deps mypkg
Defensive patterns
Strategy: validation
Validate before calling
# Validate option set before constructing the pip command.
def safe_only_deps(opts):
conflicts = []
if opts.get("no_deps"): conflicts.append("--no-deps")
if opts.get("requirement"): conflicts.append("-r/--requirement")
if opts.get("requirements_from_script"): conflicts.append("--requirements-from-script")
if opts.get("group"): conflicts.append("--group")
if opts.get("use_deprecated_legacy_resolver"): conflicts.append("legacy-resolver")
if opts.get("only_dependencies") and conflicts:
raise ValueError(f"--only-dependencies conflicts with {conflicts}")
return True Prevention
- Treat --only-dependencies as exclusive: never combine it with dependency-affecting flags in wrappers.
- Document the intent (install deps only vs. install package) explicitly in build scripts.
When it happens
Trigger: Running `pip install --only-dependencies --no-deps <pkg>`, `pip install --only-dependencies -r requirements.txt`, `pip install --only-dependencies --group dev`, or combining --only-dependencies with the legacy resolver.
Common situations: Adopting the new --only-dependencies flag in a Makefile/script that already passes -r or --no-deps; copy-pasting option combinations from a working install command without realizing the new flag conflicts; trying to install just dependencies of a locked set while also disabling deps.
Related errors
- Cannot combine '--path' with '--user' or '--local'
- --pre cannot be used with --all-releases or --only-final.
- --require-hashes and --no-require-hashes are mutually…
- --build-constraint cannot be used with --no-build-isolation.
- Can not use any platform or abi specific options unless…
AI-assisted analysis of pypa/pip@f399c37189 (2026-08-08).
Data as JSON: /api/errors/eebe45060caf760f.
Report an issue: GitHub.
Appendix: 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 f399c37189)