pypa/pip · error · CommandError

Platform and interpreter constraints using…

Error message

Platform and interpreter constraints using --python-version, --platform, --abi, or --implementation, are not supported when selecting requirements from {filename!r}

What it means

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.

Solutions

  1. Drop the platform/abi/implementation/--python-version flags and let the pylock file drive the resolution.
  2. If you genuinely need cross-platform resolution, switch to a plain requirements file (-r) instead of a pylock file.

Example fix

# before
pip install -r deps.pylock --platform manylinux2014_x86_64
# after
pip install -r deps.pylock
Defensive patterns

Strategy: validation

Validate before calling

# Detect pylock requirements files and avoid pairing them with platform flags.
from pip._internal.utils import pylock as pylock_utils
def validate_reqs(requirements_files, opts):
    restricted = any(opts.get(k) for k in ("python_version", "platforms", "abis", "implementation"))
    if restricted:
        for f in requirements_files:
            if pylock_utils.is_valid_pylock_filename(f):
                raise ValueError(f"Do not combine {f} (pylock) with platform/interpreter constraints")
    return True

Prevention

When it happens

Trigger: `pip install -r deps.pylock --platform manylinux2014_x86_64 <pkg>` or any combination of -r <pylock-file> with --platform/--abi/--implementation/--python-version.

Common situations: 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.

Related errors


AI-assisted analysis of pypa/pip@f399c37189 (2026-08-08). Data as JSON: /api/errors/99d14d5f7715b62b. Report an issue: GitHub.

Appendix: source

Thrown at src/pip/_internal/cli/cmdoptions.py:144

            "either --no-deps must be set, or --only-binary=:all: must be "
            "set and --no-binary must not be set (or must be set to "
            ":none:)."
        )

    if check_target:
        if not options.dry_run and dist_restriction_set and not options.target_dir:
            raise CommandError(
                "Can not use any platform or abi specific options unless "
                "installing via '--target' or using '--dry-run'"
            )

    if dist_restriction_set:
        # Lazy import to keep CLI startup fast
        from pip._internal.utils import pylock as pylock_utils

        for filename in options.requirements:
            if pylock_utils.is_valid_pylock_filename(filename):
                raise CommandError(
                    "Platform and interpreter constraints using "
                    "--python-version, --platform, --abi, or --implementation, "
                    f"are not supported when selecting requirements from {filename!r}"
                )


def check_build_constraints(options: Values) -> None:
    """Function for validating build constraints options.

    :param options: The OptionParser options.
    """
    if hasattr(options, "build_constraints") and options.build_constraints:
        if not options.build_isolation:
            raise CommandError(
                "--build-constraint cannot be used with --no-build-isolation."
            )

        # Import here to avoid circular imports

View on GitHub (pinned to f399c37189)