pypa/pip · error · PylockValidationError
Version in {package.sdist.filename!r} is not consistent with
Error message
Version in {package.sdist.filename!r} is not consistent with package version {str(package.version)!r} What it means
Raised as PylockValidationError (pylock.py:632) when the version parsed from sdist.filename differs from the package.version field (only checked when package.version is set). It is the sdist analogue of the wheel-version consistency check at pylock.py:611, enforcing agreement between the archive name and the package metadata.
Source
Thrown at src/pip/_vendor/packaging/pylock.py:632
f"package version {str(package.version)!r}",
context=f"wheels[{i}]",
)
if package.sdist:
try:
name, version = parse_sdist_filename(package.sdist.filename)
except Exception as e:
raise PylockValidationError(
f"Invalid sdist filename {package.sdist.filename!r}",
context="sdist",
) from e
if name != package.name:
raise PylockValidationError(
f"Name in {package.sdist.filename!r} is not consistent with "
f"package name {package.name!r}",
context="sdist",
)
if package.version and version != package.version:
raise PylockValidationError(
f"Version in {package.sdist.filename!r} is not consistent with "
f"package version {str(package.version)!r}",
context="sdist",
)
try:
for i, attestation_identity in enumerate( # noqa: B007
package.attestation_identities or []
):
_get_required(attestation_identity, str, "kind")
except Exception as e:
raise PylockValidationError(
e, context=f"attestation-identities[{i}]"
) from e
return package
@property
def is_direct(self) -> bool:
return not (self.sdist or self.wheels)View on GitHub (pinned to d7d0d0a394)
Solutions
- Align the version segment of sdist.filename with package.version.
- If the sdist filename is the source of truth, update package.version to match it.
- Regenerate the lock file end-to-end so the sdist filename and version stay in sync.
Example fix
# before [[packages]] name = "foo" version = "1.5.0" [packages.sdist] filename = "foo-1.4.0.tar.gz" # after [[packages]] name = "foo" version = "1.5.0" [packages.sdist] filename = "foo-1.5.0.tar.gz"
Defensive patterns
Strategy: validation
Validate before calling
from pip._vendor.packaging.utils import parse_sdist_filename
from pip._vendor.packaging.version import Version
def sdist_version_matches(package_version, sdist_filename):
_, ver = parse_sdist_filename(sdist_filename)
return (not package_version) or ver == Version(package_version) Type guard
null
Try / catch
from pip._vendor.packaging.pylock import PylockValidationError
try:
Pylock.from_dict(d)
except PylockValidationError as e:
handle_sdist_version_drift(e.context) Prevention
- Treat the version field and sdist filename as one unit.
- Re-run the resolver after version bumps.
When it happens
Trigger: A package entry with version='1.5.0' but sdist.filename='foo-1.4.0.tar.gz'. Triggered during Pylock.from_dict() / Pylock.validate() after a successful name match.
Common situations: Stale sdist filename left in the lock after a version bump; merging lock entries from two resolver runs that disagree on the version.
Related errors
- Version in {wheel.filename!r} is not consistent with package
- Invalid sdist filename {package.sdist.filename!r}
- Name in {package.sdist.filename!r} is not consistent with pa
- Platform and interpreter constraints using --python-version,
- Invalid requirement: {req_as_string!r}: {exc}
AI-assisted analysis of pypa/pip@d7d0d0a394 (2026-08-04).
Data as JSON: /data/errors/a5c89b28def87051.json.
Report an issue: GitHub.