{"record":{"id":"99d14d5f7715b62b","repo":"pypa/pip","slug":"platform-and-interpreter-constraints-using-pytho","errorCode":null,"errorMessage":"Platform and interpreter constraints using --python-version, --platform, --abi, or --implementation, are not supported when selecting requirements from {filename!r}","messagePattern":"Platform and interpreter constraints using --python-version, --platform, --abi, or --implementation, are not supported when selecting requirements from (.+?)","errorType":"exception","errorClass":"CommandError","httpStatus":null,"severity":"error","filePath":"src/pip/_internal/cli/cmdoptions.py","lineNumber":144,"sourceCode":"            \"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:\n    \"\"\"Function for validating build constraints options.\n\n    :param options: The OptionParser options.\n    \"\"\"\n    if hasattr(options, \"build_constraints\") and options.build_constraints:\n        if not options.build_isolation:\n            raise CommandError(\n                \"--build-constraint cannot be used with --no-build-isolation.\"\n            )\n\n        # Import here to avoid circular imports","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/pypa/pip/blob/f399c3718970b1b0e2478dac5296eb62679a9b86/src/pip/_internal/cli/cmdoptions.py#L126-L162","documentation":"Raised as CommandError by check_dist_restriction (cmdoptions.py:144) when a requirements file (passed via -r) whose name matches a valid pylock filename pattern is combined with platform/interpreter constraints. Pylock files are self-describing lock files that already pin the exact platform/interpreter set they were resolved for, so letting the user override those constraints on top would produce an inconsistent resolution. The check at lines 138-148 iterates options.requirements and tests each with pylock_utils.is_valid_pylock_filename.","triggerScenarios":"`pip install -r deps.pylock --platform manylinux2014_x86_64 <pkg>` or any combination of -r <pylock-file> with --platform/--abi/--implementation/--python-version.","commonSituations":"Migrating a lock-file workflow to pip and not realizing the new pylock format already encodes platform constraints; mixing a pylock requirements file with legacy cross-platform flags.","solutions":["Drop the platform/abi/implementation/--python-version flags and let the pylock file drive the resolution.","If you genuinely need cross-platform resolution, switch to a plain requirements file (-r) instead of a pylock file."],"exampleFix":"# before\npip install -r deps.pylock --platform manylinux2014_x86_64\n# after\npip install -r deps.pylock","handlingStrategy":"validation","validationCode":"# Detect pylock requirements files and avoid pairing them with platform flags.\nfrom pip._internal.utils import pylock as pylock_utils\ndef validate_reqs(requirements_files, opts):\n    restricted = any(opts.get(k) for k in (\"python_version\", \"platforms\", \"abis\", \"implementation\"))\n    if restricted:\n        for f in requirements_files:\n            if pylock_utils.is_valid_pylock_filename(f):\n                raise ValueError(f\"Do not combine {f} (pylock) with platform/interpreter constraints\")\n    return True","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat pylock files as fully self-describing: never override their encoded constraints.","Use plain -r requirements files when you need manual platform control."],"tags":["cli-options","platform","pylock","requirements-file","command-error"],"backgroundTag":null,"analyzedSha":"f399c3718970b1b0e2478dac5296eb62679a9b86","analyzedAt":"2026-08-08T23:01:42.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}