{"record":{"id":"1173675d521235a9","repo":"pypa/pip","slug":"name-in-wheel-filename-r-is-not-consistent-with","errorCode":null,"errorMessage":"Name in {wheel.filename!r} is not consistent with package name {package.name!r}","messagePattern":"Name in (.+?) is not consistent with package name (.+?)","errorType":"validation","errorClass":"PylockValidationError","httpStatus":null,"severity":"error","filePath":"src/pip/_vendor/packaging/pylock.py","lineNumber":622,"sourceCode":"        if distributions > 0 and direct_urls > 0:\n            raise PylockValidationError(\n                \"None of vcs, directory, archive must be set if sdist or wheels are set\"\n            )\n        if distributions == 0 and direct_urls != 1:\n            raise PylockValidationError(\n                \"Exactly one of vcs, directory, archive must be set \"\n                \"if sdist and wheels are not set\"\n            )\n        for i, wheel in enumerate(package.wheels or []):\n            try:\n                (name, version, _, _) = parse_wheel_filename(wheel.filename)\n            except Exception as e:\n                raise PylockValidationError(\n                    f\"Invalid wheel filename {wheel.filename!r}\",\n                    context=f\"wheels[{i}]\",\n                ) from e\n            if name != package.name:\n                raise PylockValidationError(\n                    f\"Name in {wheel.filename!r} is not consistent with \"\n                    f\"package name {package.name!r}\",\n                    context=f\"wheels[{i}]\",\n                )\n            if package.version and version != package.version:\n                raise PylockValidationError(\n                    f\"Version in {wheel.filename!r} is not consistent with \"\n                    f\"package version {str(package.version)!r}\",\n                    context=f\"wheels[{i}]\",\n                )\n        if package.sdist:\n            try:\n                name, version = parse_sdist_filename(package.sdist.filename)\n            except Exception as e:\n                raise PylockValidationError(\n                    f\"Invalid sdist filename {package.sdist.filename!r}\",\n                    context=\"sdist\",\n                ) from e","sourceCodeStart":604,"sourceCodeEnd":640,"githubUrl":"https://github.com/pypa/pip/blob/f399c3718970b1b0e2478dac5296eb62679a9b86/src/pip/_vendor/packaging/pylock.py#L604-L640","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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()."],"exampleFix":"# before\n[[packages]]\nname = \"requests\"\n  [[packages.wheels]]\n  filename = \"urllib3-2.0.0-py3-none-any.whl\"\n\n# after\n[[packages]]\nname = \"urllib3\"\n  [[packages.wheels]]\n  filename = \"urllib3-2.0.0-py3-none-any.whl\"","handlingStrategy":"validation","validationCode":"from packaging.utils import parse_wheel_filename, canonicalize_name\n\ndef wheel_name_consistent(filename: str, package_name: str) -> bool:\n    try:\n        name, *_ = parse_wheel_filename(filename)\n    except Exception:\n        return False\n    return canonicalize_name(name) == canonicalize_name(package_name)\n\nfor p in toml_dict.get('packages', []):\n    for w in p.get('wheels', []) or []:\n        assert wheel_name_consistent(w['filename'], p['name']), w['filename']","typeGuard":"null","tryCatchPattern":"from packaging.pylock import PylockValidationError\ntry:\n    Pylock.from_dict(toml_dict)\nexcept PylockValidationError as e:\n    # e.context pinpoints wheels[i]; fix that entry's filename/package name\n    report(e.context, e.message)","preventionTips":["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."],"tags":["pylock","packaging","validation","naming","wheel"],"backgroundTag":null,"analyzedSha":"f399c3718970b1b0e2478dac5296eb62679a9b86","analyzedAt":"2026-08-08T23:01:42.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}