{"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/d7d0d0a39494e28ec1c407bd0680e4a4d1067791/src/pip/_internal/cli/cmdoptions.py#L115-L151","documentation":"Raised by check_dist_restriction() in cmdoptions.py:133 when platform/ABI options (--python-version, --platform, --abi, --implementation) are used during a regular install (not --dry-run) without specifying a --target directory. Cross-platform installation must go to a specific target directory to avoid polluting the current environment with incompatible packages.","triggerScenarios":"Calling `pip install --platform linux_x86_64 --python-version 3.12 --only-binary=:all: numpy` without `--target ./libs`. The check_target parameter is True for install commands.","commonSituations":"Building Docker images for a different architecture. Preparing a deployment directory for another platform. Forgetting that cross-platform installs cannot go into the current environment's site-packages.","solutions":["Add `--target <directory>` to specify where cross-platform packages should be installed.","Alternatively, use `--dry-run` if you only want to check resolution without installing.","If you actually want to install for the current platform, remove the --platform/--abi/--implementation/--python-version options."],"exampleFix":"# before\npip install --platform linux_x86_64 --python-version 312 --only-binary=:all: numpy\n\n# after\npip install --platform linux_x86_64 --python-version 312 --only-binary=:all: --target ./vendor numpy","handlingStrategy":"validation","validationCode":"def validate_cross_platform_has_target(options):\n    \"\"\"Ensure cross-platform install has a target or dry-run.\"\"\"\n    dist_set = any([options.get('python_version'), options.get('platforms'),\n                    options.get('abis'), options.get('implementation')])\n    if not dist_set:\n        return True\n    return options.get('target_dir') is not None or options.get('dry_run', False)","typeGuard":null,"tryCatchPattern":"from pip._internal.exceptions import CommandError\ntry:\n    # cross-platform install\nexcept CommandError as e:\n    if \"'--target'\" in str(e):\n        # add --target ./libs and retry\n","preventionTips":["Always specify --target when cross-platform installing.","Use --dry-run to test resolution without installing.","Remove platform flags if installing for the current environment."],"tags":["cli","cross-platform","target","option-conflict","validation"],"analyzedSha":"d7d0d0a39494e28ec1c407bd0680e4a4d1067791","analyzedAt":"2026-08-04T20:55:04.259Z","schemaVersion":2}