pypa/pip · error · PylockValidationError
Name in {package.sdist.filename!r} is not consistent with pa
Error message
Name in {package.sdist.filename!r} is not consistent with package name {package.name!r} What it means
Raised as PylockValidationError (pylock.py:626) when the project name parsed from sdist.filename does not equal the package.name field after canonicalization. It enforces that the distribution name embedded in the sdist archive name matches the declared package name, mirroring the wheel-name check.
Source
Thrown at src/pip/_vendor/packaging/pylock.py:626
f"package name {package.name!r}",
context=f"wheels[{i}]",
)
if package.version and version != package.version:
raise PylockValidationError(
f"Version in {wheel.filename!r} is not consistent with "
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}]"View on GitHub (pinned to d7d0d0a394)
Solutions
- Make sdist.filename's name segment canonicalize to the same value as package.name.
- If the filename is authoritative, update package.name to match (then re-normalize).
- Regenerate the lock file to reconcile both fields automatically.
Example fix
# before [[packages]] name = "foo_bar" [packages.sdist] filename = "foo-baz-1.0.tar.gz" # after [[packages]] name = "foo_bar" [packages.sdist] filename = "foo_bar-1.0.tar.gz"
Defensive patterns
Strategy: validation
Validate before calling
from pip._vendor.packaging.utils import parse_sdist_filename, canonicalize_name
def sdist_name_matches(package_name, sdist_filename):
name, _ = parse_sdist_filename(sdist_filename)
return canonicalize_name(name) == canonicalize_name(package_name) Type guard
null
Try / catch
from pip._vendor.packaging.pylock import PylockValidationError
try:
Pylock.from_dict(d)
except PylockValidationError as e:
report_name_mismatch(e.context, e.message) Prevention
- Canonicalize package names with canonicalize_name before comparing.
- Regenerate locks after any project rename.
When it happens
Trigger: A package entry where name='Foo' but sdist.filename='foo-bar-1.0.tar.gz', or any case where the normalized parsed name differs from the normalized package.name. Reached via Pylock.from_dict() / Pylock.validate().
Common situations: Renaming a project without updating the lock, or a resolver that canonicalized names inconsistently between the name field and the filename. Typos in manually authored locks.
Related errors
- Version in {wheel.filename!r} is not consistent with package
- Invalid sdist filename {package.sdist.filename!r}
- Version in {package.sdist.filename!r} is not consistent with
- Platform and interpreter constraints using --python-version,
- Requested {ireq} has inconsistent Name: expected {f_val!r},
AI-assisted analysis of pypa/pip@d7d0d0a394 (2026-08-04).
Data as JSON: /data/errors/83e4ecf41032c700.json.
Report an issue: GitHub.