pypa/pip · error · PylockUnsupportedVersionError

pylock version is not supported

Error message

pylock version {pylock.lock_version} is not supported

What it means

PylockUnsupportedVersionError (a PylockValidationError subclass) raised by Pylock._from_dict when the lock's lock-version is not in the supported range [1.0, 2.0). The library only implements PEP 751 lock version 1.x; a 0.x or 2.0+ file is rejected outright.

Solutions

  1. Open pylock.toml and read the top-level lock-version field.
  2. If it is 0.x or 2.0+, set it to a supported value like '1.0' only if the rest of the schema is actually 1.x-compatible; otherwise regenerate the lock.
  3. Upgrade pip/packaging to a version that supports the lock-version you have, if available.
  4. Re-run Pylock.from_dict; if lock-version > 1.0 but < 2.0 you may also see a warning that the minor version is unsupported — verify behavior.

Example fix

# before
lock-version = "2.0"

# after
lock-version = "1.0"
Defensive patterns

Strategy: validation

Validate before calling

from packaging.version import Version

def supported_lock_version(v) -> bool:
    try:
        lv = Version(str(v))
    except Exception:
        return False
    return Version('1') <= lv < Version('2')

assert supported_lock_version(toml_dict['lock-version']), toml_dict['lock-version']

Type guard

null

Try / catch

from packaging.pylock import Pylock, PylockUnsupportedVersionError
try:
    Pylock.from_dict(toml_dict)
except PylockUnsupportedVersionError as e:
    # read lock-version; upgrade packaging or pin the lock to a 1.x version
    report(e.message)

Prevention

When it happens

Trigger: Calling Pylock.from_dict on a TOML dict whose lock-version = '0.1' (draft/older schema), '2.0' (a newer major revision this vendored packaging does not yet support), or a non-PEP440 string. The check is 'Version("1") <= lock_version < Version("2")'. A lock-version above '1.0' but below '2.0' also emits a warning that the minor version is unsupported.

Common situations: Reading a lock produced by a newer tool that writes lock-version 2.x; a hand-authored file using lock-version 1; upgrading packaging and encountering a lock from the future.

Related errors


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

Appendix: source

Thrown at src/pip/_vendor/packaging/pylock.py:721

        object.__setattr__(self, "created_by", created_by)
        object.__setattr__(self, "packages", packages)
        object.__setattr__(self, "tool", tool)

    @classmethod
    def _from_dict(cls, d: Mapping[str, Any]) -> Self:
        pylock = cls(
            lock_version=_get_required_as(d, str, Version, "lock-version"),
            environments=_get_sequence_as(d, str, Marker, "environments"),
            extras=_get_sequence_as(d, str, _validate_normalized_name, "extras"),
            dependency_groups=_get_sequence(d, str, "dependency-groups"),
            default_groups=_get_sequence(d, str, "default-groups"),
            created_by=_get_required(d, str, "created-by"),
            requires_python=_get_as(d, str, SpecifierSet, "requires-python"),
            packages=_get_required_sequence_of_objects(d, Package, "packages"),
            tool=_get(d, Mapping, "tool"),  # type: ignore[type-abstract]
        )
        if not Version("1") <= pylock.lock_version < Version("2"):
            raise PylockUnsupportedVersionError(
                f"pylock version {pylock.lock_version} is not supported"
            )
        if pylock.lock_version > Version("1.0"):
            _logger.warning(
                "pylock minor version %s is not supported", pylock.lock_version
            )
        return pylock

    @classmethod
    def from_dict(cls, d: Mapping[str, Any], /) -> Self:
        """Create and validate a Pylock instance from a TOML dictionary.

        Raises :class:`PylockValidationError` if the input data is not
        spec-compliant.
        """
        return cls._from_dict(d)

    def to_dict(self) -> Mapping[str, Any]:

View on GitHub (pinned to f399c37189)