{"record":{"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/f399c3718970b1b0e2478dac5296eb62679a9b86/src/pip/_internal/cli/cmdoptions.py#L73-L109","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# before\npip install --only-dependencies --no-deps mypkg\n# after (pick one intent)\npip install --only-dependencies mypkg\n# or\npip install --no-deps mypkg","handlingStrategy":"validation","validationCode":"# Validate option set before constructing the pip command.\ndef safe_only_deps(opts):\n    conflicts = []\n    if opts.get(\"no_deps\"): conflicts.append(\"--no-deps\")\n    if opts.get(\"requirement\"): conflicts.append(\"-r/--requirement\")\n    if opts.get(\"requirements_from_script\"): conflicts.append(\"--requirements-from-script\")\n    if opts.get(\"group\"): conflicts.append(\"--group\")\n    if opts.get(\"use_deprecated_legacy_resolver\"): conflicts.append(\"legacy-resolver\")\n    if opts.get(\"only_dependencies\") and conflicts:\n        raise ValueError(f\"--only-dependencies conflicts with {conflicts}\")\n    return True","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["cli-options","only-dependencies","conflict","command-error"],"backgroundTag":null,"analyzedSha":"f399c3718970b1b0e2478dac5296eb62679a9b86","analyzedAt":"2026-08-08T23:01:42.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}