pypa/pip · error · PylockValidationError
Name in {wheel.filename!r} is not consistent with package na
Error message
Name in {wheel.filename!r} is not consistent with package name {package.name!r} What it means
Raised as PylockValidationError by Package._from_dict in packaging.pylock when the wheel filename parses successfully but its embedded distribution name does not match the package's normalized name. pylock requires every wheel in a package entry to belong to that exact package, preventing accidental cross-package wheels.
Source
Thrown at src/pip/_vendor/packaging/pylock.py:606
if distributions > 0 and direct_urls > 0:
raise PylockValidationError(
"None of vcs, directory, archive must be set if sdist or wheels are set"
)
if distributions == 0 and direct_urls != 1:
raise PylockValidationError(
"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 eView on GitHub (pinned to d7d0d0a394)
Solutions
- Move the wheel into the package entry whose name matches the wheel's distribution name.
- Rename the package entry to the wheel's distribution name (after normalization).
- Regenerate the lockfile so each wheel is filed under its correct package.
- Verify the wheel filename with packaging.utils.parse_wheel_filename and compare canonical names before adding.
Example fix
# before
[packages]
name = \"foo\"
wheels = [{ name = \"bar-1.0-py3-none-any.whl\", hashes = {...} }]
# after
[packages]
name = \"bar\"
wheels = [{ name = \"bar-1.0-py3-none-any.whl\", hashes = {...} }] Defensive patterns
Strategy: validation
Validate before calling
from packaging.utils import parse_wheel_filename, canonicalize_name
def wheel_matches_package(wheel_fname: str, package_name: str) -> bool:
try:
name, *_ = parse_wheel_filename(wheel_fname)
except Exception:
return False
return name == canonicalize_name(package_name) Type guard
from packaging.utils import parse_wheel_filename, canonicalize_name
def is_consistent_wheel(wheel_fname: str, package_name: str) -> bool:
try:
name, *_ = parse_wheel_filename(wheel_fname)
except Exception:
return False
return name == canonicalize_name(package_name) Try / catch
try:
PylockFile.from_dict(data)
except PylockValidationError as e:
if 'not consistent with package name' in str(e):
move_wheel_to_correct_package(e.context) Prevention
- File each wheel under the package whose canonical name matches the wheel's distribution name.
- Validate wheel/package name consistency before loading.
- Regenerate the lockfile so wheels are filed correctly.
- Avoid merging package entries from different sources.
When it happens
Trigger: A package with name = \"foo\" containing a wheel named 'bar-1.0-py3-none-any.whl'; a wheel whose name is a non-normalized variant that does not equal the canonicalized package name (e.g. wheel 'Foo' vs package 'foo' after canonicalization differs only if the wheel filename's distribution portion does not canonicalize to the package name). The check compares parse_wheel_filename's returned name to package.name.
Common situations: Lockfile entries merged from multiple packages incorrectly; a fork/renamed project whose wheel still ships under the old name; a wheel copied into the wrong package block during hand-editing.
Related errors
- Cannot determine wheel filename
- Invalid wheel filename {wheel.filename!r}
- path or url must be provided
- Cannot determine sdist filename
- None of vcs, directory, archive must be set if sdist or whee
AI-assisted analysis of pypa/pip@d7d0d0a394 (2026-08-04).
Data as JSON: /data/errors/1173675d521235a9.json.
Report an issue: GitHub.