{"id":"eebe45060caf760f","repo":"pypa/pip","slug":"cannot-use-only-dependencies-in-combination-wi","errorCode":null,"errorMessage":"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","messagePattern":"Cannot use '--only-dependencies' in combination with (.+?)\\. If this is unexpected, please refer to the user guide:\n\n    https://pip\\.pypa\\.io/en/stable/user_guide/#installing-only-dependencies","errorType":"exception","errorClass":"CommandError","httpStatus":null,"severity":"error","filePath":"src/pip/_internal/cli/cmdoptions.py","lineNumber":91,"sourceCode":"    \"\"\"\n    if not options.only_dependencies:\n        return\n    conflicts = []\n    if options.ignore_dependencies:\n        conflicts.append(\"'--no-deps'\")\n    if \"legacy-resolver\" in options.deprecated_features_enabled:\n        conflicts.append(\"'--use-deprecated legacy-resolver'\")\n    if options.requirements:\n        conflicts.append(\"'--requirement'\")\n    if options.requirements_from_scripts:\n        conflicts.append(\"'--requirements-from-script'\")\n    if options.dependency_groups:\n        conflicts.append(\"'--group'\")\n    if conflicts:\n        if len(conflicts) > 1:\n            conflicts[-1] = \"or \" + conflicts[-1]\n        conflict_message = \", \".join(conflicts)\n        raise CommandError(\n            f\"Cannot use '--only-dependencies' in combination with {conflict_message}. \"\n            \"If this is unexpected, please refer to the user guide:\\n\"\n            \"\\n\"\n            \"    https://pip.pypa.io/en/stable/user_guide/#installing-only-dependencies\"\n        )\n\n\ndef check_dist_restriction(options: Values, check_target: bool = False) -> None:\n    \"\"\"Function for determining if custom platform options are allowed.\n\n    :param options: The OptionParser options.\n    :param check_target: Whether or not to check if --target is being used.\n    \"\"\"\n    dist_restriction_set = any(\n        [\n            options.python_version,\n            options.platforms,\n            options.abis,","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/pypa/pip/blob/d7d0d0a39494e28ec1c407bd0680e4a4d1067791/src/pip/_internal/cli/cmdoptions.py#L73-L109","documentation":"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.","triggerScenarios":"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>`.","commonSituations":"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).","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."],"exampleFix":"# before\npip install --only-deps --no-deps mypackage\n\n# after\npip install --only-deps mypackage\n# (remove --no-deps; --only-deps already handles dependency-only install)","handlingStrategy":"validation","validationCode":"def validate_only_deps_options(options):\n    \"\"\"Validate --only-deps doesn't conflict with incompatible options.\"\"\"\n    if not options.get('only_dependencies'):\n        return True\n    conflicts = ['no-deps', 'legacy-resolver', 'requirement', 'requirements-from-script', 'group']\n    for c in conflicts:\n        if options.get(c):\n            return False\n    return True","typeGuard":null,"tryCatchPattern":"from pip._internal.exceptions import CommandError\ntry:\n    # pip install invocation\nexcept CommandError as e:\n    if \"'--only-dependencies'\" in str(e):\n        # remove conflicting option and retry\n","preventionTips":["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."],"tags":["cli","option-conflict","only-dependencies","validation"],"analyzedSha":"d7d0d0a39494e28ec1c407bd0680e4a4d1067791","analyzedAt":"2026-08-04T20:55:04.259Z","schemaVersion":2}