{"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/d7d0d0a39494e28ec1c407bd0680e4a4d1067791/src/pip/_internal/cli/cmdoptions.py#L126-L162","documentation":"Raised by check_dist_restriction() in cmdoptions.py:144 when platform/interpreter constraint options are used simultaneously with a pylock.toml requirements file (detected via is_valid_pylock_filename). pylock.toml files already contain fully resolved, platform-specific lock data, so applying additional platform constraints on top is unsupported and could produce incorrect results.","triggerScenarios":"Calling `pip install -r pylock.toml --platform linux_x86_64 --python-version 3.12` or similar combinations where a pylock file is used as a requirements source alongside any of --python-version, --platform, --abi, or --implementation.","commonSituations":"Using the experimental pylock.toml support and trying to filter by platform at install time. Migrating from requirements.txt to pylock.toml but keeping old cross-platform flags in scripts.","solutions":["Remove all platform/interpreter constraint options (--python-version, --platform, --abi, --implementation) when using pylock.toml.","If you need platform-specific locks, generate separate pylock.toml files per platform.","Use a standard requirements.txt file instead if you need cross-platform constraints."],"exampleFix":"# before\npip install -r pylock.toml --platform linux_x86_64 --python-version 312\n\n# after\npip install -r pylock.toml","handlingStrategy":"validation","validationCode":"def validate_pylock_no_platform_opts(filenames, options):\n    \"\"\"Ensure pylock.toml files are not used with platform constraints.\"\"\"\n    import re\n    pylock_pattern = re.compile(r'.*pylock.*\\.toml$', re.IGNORECASE)\n    has_pylock = any(pylock_pattern.match(f) for f in filenames)\n    dist_set = any([options.get('python_version'), options.get('platforms'),\n                    options.get('abis'), options.get('implementation')])\n    return not (has_pylock and dist_set)","typeGuard":null,"tryCatchPattern":"from pip._internal.exceptions import CommandError\ntry:\n    # install with pylock + platform flags\nexcept CommandError as e:\n    if 'pylock' in str(e).lower() or 'not supported' in str(e):\n        # remove platform flags and retry\n","preventionTips":["Never combine pylock.toml with platform constraint flags.","Generate separate pylock.toml files per platform.","Use standard requirements.txt if you need cross-platform constraints."],"tags":["cli","pylock","cross-platform","option-conflict","validation"],"analyzedSha":"d7d0d0a39494e28ec1c407bd0680e4a4d1067791","analyzedAt":"2026-08-04T20:55:04.259Z","schemaVersion":2}