pypa/pip · error · PylockValidationError
Version in {wheel.filename!r} is not consistent with package
Error message
Version in {wheel.filename!r} is not consistent with package version {str(package.version)!r} What it means
Raised by Pylock.Package._from_dict (pylock.py:611-616) as a PylockValidationError when a wheel entry's filename encodes a version that differs from the package's declared 'version' field. packaging parses the wheel filename with parse_wheel_filename and compares the resulting version against package.version only when package.version is set. It enforces PEP 753's rule that wheel filenames and the package version metadata must agree.
Source
Thrown at src/pip/_vendor/packaging/pylock.py:612
"Exactly one of vcs, directory, archive must be set "
"if sdist and wheels are not set"
)
for i, wheel in enumerate(package.wheels or []):
try:
(name, version, _, _) = parse_wheel_filename(wheel.filename)
except Exception as e:
raise PylockValidationError(
f"Invalid wheel filename {wheel.filename!r}",
context=f"wheels[{i}]",
) from e
if name != package.name:
raise PylockValidationError(
f"Name in {wheel.filename!r} is not consistent with "
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",
)View on GitHub (pinned to d7d0d0a394)
Solutions
- Open the pylock TOML and find packages[<index>] reported in the error context (e.g. 'wheels[2]'); align the wheel filename's version segment with the package.version field.
- Regenerate the lock file with the tool that produced it (uv/pip) so filenames and versions stay consistent.
- If the wheel filename is correct, update package.version to match it; if the version field is correct, replace the wheel filename.
Example fix
# before
[[packages]]
name = "foo"
version = "1.2.4"
wheels = [{ filename = "foo-1.2.3-py3-none-any.whl", url = "..." }]
# after
[[packages]]
name = "foo"
version = "1.2.4"
wheels = [{ filename = "foo-1.2.4-py3-none-any.whl", url = "..." }] Defensive patterns
Strategy: validation
Validate before calling
from pip._vendor.packaging.utils import parse_wheel_filename
from pip._vendor.packaging.version import Version
def wheel_version_matches(package_name, package_version, wheel_filename):
name, ver, _, _ = parse_wheel_filename(wheel_filename)
return name == package_name and (not package_version or ver == Version(package_version)) Type guard
null
Try / catch
from pip._vendor.packaging.pylock import PylockValidationError
try:
Pylock.from_dict(toml_dict)
except PylockValidationError as e:
# e.context points at 'packages[N].wheels[M]'
log.error('lock wheel/version mismatch at %s: %s', e.context, e.message) Prevention
- Always generate pylock files with a spec-compliant resolver rather than editing by hand.
- Treat package.version and wheel filenames as a single atomic unit when editing locks.
When it happens
Trigger: Loading a pylock TOML via Pylock.from_dict() where a [[packages.wheels]] entry has filename='foo-1.2.3-py3-none-any.whl' but the parent [packages] table sets version='1.2.4'. Also reached indirectly through Pylock.validate(), which round-trips to_dict() back through _from_dict.
Common situations: A lock file was hand-edited or generated by a buggy resolver that wrote a wheel filename from one source and the version from another. Re-publishing a project at a new version while leaving stale wheel filenames in the lock also triggers it.
Related errors
- Version in {package.sdist.filename!r} is not consistent with
- 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/d5903571b7065fb6.json.
Report an issue: GitHub.