pypa/pip · error · PylockValidationError
Name in is not consistent with package name
Error message
Name in {wheel.filename!r} is not consistent with package name {package.name!r} What it means
PylockValidationError: the project name parsed out of a wheel filename does not match the package's declared 'name' field (after PEP 503 normalization). PEP 751 requires a wheel filename to be consistent with its package entry, so a mismatch signals a corrupt or misassembled lock.
Solutions
- Compare the name segment (everything before the first dash) of the wheel filename against the package's name field.
- Move the wheel entry to the package whose name it matches, or fix the filename so its leading name segment matches package.name (normalization is applied, so 'Foo_Bar' and 'foo-bar' are consistent).
- Regenerate the lock file if the mismatch originates from the producer tool.
- Re-validate with Pylock.validate().
Example fix
# before [[packages]] name = "requests" [[packages.wheels]] filename = "urllib3-2.0.0-py3-none-any.whl" # after [[packages]] name = "urllib3" [[packages.wheels]] filename = "urllib3-2.0.0-py3-none-any.whl"
Defensive patterns
Strategy: validation
Validate before calling
from packaging.utils import parse_wheel_filename, canonicalize_name
def wheel_name_consistent(filename: str, package_name: str) -> bool:
try:
name, *_ = parse_wheel_filename(filename)
except Exception:
return False
return canonicalize_name(name) == canonicalize_name(package_name)
for p in toml_dict.get('packages', []):
for w in p.get('wheels', []) or []:
assert wheel_name_consistent(w['filename'], p['name']), w['filename'] Type guard
null
Try / catch
from packaging.pylock import PylockValidationError
try:
Pylock.from_dict(toml_dict)
except PylockValidationError as e:
# e.context pinpoints wheels[i]; fix that entry's filename/package name
report(e.context, e.message) Prevention
- When moving a wheel entry between package blocks, always verify the leading name segment matches the target package.
- Normalize names for comparison; PEP 503 treats 'Foo_Bar' and 'foo-bar' as equal.
- Regenerate the lock after renaming a fork so wheel filenames carry the new name.
When it happens
Trigger: During Package validation, for each wheel in packages[*].wheels, the name segment from parse_wheel_filename(wheel.filename) is compared to package.name. Triggers when e.g. name="requests" but a wheel filename is 'urllib3-2.0.0-py3-none-any.whl' (wrong wheel attached to the wrong package), or a renamed fork whose wheel still carries the old name.
Common situations: Copy-pasting a wheel entry between package blocks when editing pylock.toml; a fork/rename where the wheel was not rebuilt under the new name; a lock generator bug that indexes wheels by the wrong distribution.
Related errors
- Invalid wheel filename
- Name in is not consistent with package name
- Version in is not consistent with package version
- Cannot determine wheel filename
- .dist-info directory
AI-assisted analysis of pypa/pip@f399c37189 (2026-08-08).
Data as JSON: /api/errors/1173675d521235a9.
Report an issue: GitHub.
Appendix: source
Thrown at src/pip/_vendor/packaging/pylock.py:622
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 f399c37189)