{"record":{"id":"459d3a57ed3fb4bd","repo":"pypa/pip","slug":"can-not-use-any-platform-or-abi-specific-options-u","errorCode":null,"errorMessage":"Can not use any platform or abi specific options unless installing via '--target' or using '--dry-run'","messagePattern":"Can not use any platform or abi specific options unless installing via '--target' or using '--dry-run'","errorType":"exception","errorClass":"CommandError","httpStatus":null,"severity":"error","filePath":"src/pip/_internal/cli/cmdoptions.py","lineNumber":133,"sourceCode":"    sdist_dependencies_allowed = (\n        options.format_control != binary_only and not options.ignore_dependencies\n    )\n\n    # Installations or downloads using dist restrictions must not combine\n    # source distributions and dist-specific wheels, as they are not\n    # guaranteed to be locally compatible.\n    if dist_restriction_set and sdist_dependencies_allowed:\n        raise CommandError(\n            \"When restricting platform and interpreter constraints using \"\n            \"--python-version, --platform, --abi, or --implementation, \"\n            \"either --no-deps must be set, or --only-binary=:all: must be \"\n            \"set and --no-binary must not be set (or must be set to \"\n            \":none:).\"\n        )\n\n    if check_target:\n        if not options.dry_run and dist_restriction_set and not options.target_dir:\n            raise CommandError(\n                \"Can not use any platform or abi specific options unless \"\n                \"installing via '--target' or using '--dry-run'\"\n            )\n\n    if dist_restriction_set:\n        # Lazy import to keep CLI startup fast\n        from pip._internal.utils import pylock as pylock_utils\n\n        for filename in options.requirements:\n            if pylock_utils.is_valid_pylock_filename(filename):\n                raise CommandError(\n                    \"Platform and interpreter constraints using \"\n                    \"--python-version, --platform, --abi, or --implementation, \"\n                    f\"are not supported when selecting requirements from {filename!r}\"\n                )\n\n\ndef check_build_constraints(options: Values) -> None:","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/pypa/pip/blob/f399c3718970b1b0e2478dac5296eb62679a9b86/src/pip/_internal/cli/cmdoptions.py#L115-L151","documentation":"Raised as CommandError by check_dist_restriction with check_target=True (cmdoptions.py:133). When dist-restriction options are set (lines 105-112) the command must either be a dry run or install into an explicit --target directory, because platform/abi-specific artifacts only make sense when you are NOT installing into the running interpreter's environment. The guard at line 132 fires when not dry_run AND a restriction is set AND no target_dir.","triggerScenarios":"`pip install --platform manylinux2014_x86_64 <pkg>` (install, no --target, no --dry-run), or any install using --python-version/--abi/--implementation without --target.","commonSituations":"Confusing `pip install` with `pip download` when doing cross-platform resolution; forgetting --target when setting up an offline bundle for another machine.","solutions":["Use `pip download` instead of `pip install` for cross-platform fetching.","Add `--target <dir>` so artifacts land in a separate directory rather than the live environment.","Add `--dry-run` to validate the resolution without writing anything."],"exampleFix":"# before\npip install --platform manylinux2014_x86_64 --python-version 39 --only-binary=:all: numpy\n# after\npip download --platform manylinux2014_x86_64 --python-version 39 --only-binary=:all: numpy","handlingStrategy":"validation","validationCode":"# Choose download vs install based on whether constraints are set.\ndef pick_command(opts):\n    restricted = any(opts.get(k) for k in (\"python_version\", \"platforms\", \"abis\", \"implementation\"))\n    if restricted and opts.get(\"command\") == \"install\" and not (opts.get(\"target_dir\") or opts.get(\"dry_run\")):\n        raise ValueError(\"Use 'pip download', or add --target/--dry-run, when cross-targeting\")\n    return True","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Default to `pip download` (not install) for any cross-platform/cross-abi work.","Use --dry-run to validate resolution before committing to a target directory."],"tags":["cli-options","platform","target","dry-run","command-error"],"backgroundTag":null,"analyzedSha":"f399c3718970b1b0e2478dac5296eb62679a9b86","analyzedAt":"2026-08-08T23:01:42.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}