{"record":{"id":"bf738e81189fe25c","repo":"pypa/pip","slug":"bad-metadata-in-dist-invalid-metadata-entry-na","errorCode":null,"errorMessage":"Bad metadata in {dist} (invalid metadata entry 'name')","messagePattern":"Bad metadata in (.+?) \\(invalid metadata entry 'name'\\)","errorType":"exception","errorClass":"BadMetadata","httpStatus":null,"severity":"error","filePath":"src/pip/_internal/metadata/importlib/_compat.py","lineNumber":86,"sourceCode":"    if suffix == \".egg-info\":\n        name = stem.split(\"-\", 1)[0]\n        return name, None\n\n    return None, None\n\n\ndef get_dist_canonical_name(dist: importlib.metadata.Distribution) -> NormalizedName:\n    \"\"\"Get the distribution's normalized name.\n\n    The ``name`` attribute is only available in Python 3.10 or later. We are\n    targeting exactly that, but Mypy does not know this.\n    \"\"\"\n    if name := parse_name_and_version_from_info_directory(dist)[0]:\n        return canonicalize_name(name)\n\n    name = cast(Any, dist).name\n    if not isinstance(name, str):\n        raise BadMetadata(dist, reason=\"invalid metadata entry 'name'\")\n    return canonicalize_name(name)\n","sourceCodeStart":68,"sourceCodeEnd":88,"githubUrl":"https://github.com/pypa/pip/blob/f399c3718970b1b0e2478dac5296eb62679a9b86/src/pip/_internal/metadata/importlib/_compat.py#L68-L88","documentation":"Raised as BadMetadata(dist, reason=\"invalid metadata entry 'name'\") from get_dist_canonical_name in _compat.py:81-86. After trying to derive the name from the .dist-info directory name, pip falls back to the Distribution.name attribute; if that value is not a str (e.g. None because the METADATA 'Name' field is missing or corrupt), BadMetadata is raised.","triggerScenarios":"Reading metadata for a distribution whose info directory name cannot be parsed for a name AND whose dist.name resolves to a non-string (typically None). Encountered when pip introspects a broken/installed distribution.","commonSituations":"A hand-edited or truncated METADATA/PKG-INFO file with no 'Name' header; a distribution installed by a buggy installer that wrote an empty name; metadata generated by an old/broken build backend.","solutions":["Reinstall the offending package from a known-good source so its METADATA 'Name' field is restored.","Manually fix or remove the corrupt .dist-info/.egg-info directory under site-packages.","If building the package yourself, ensure the build backend emits a valid 'Name' in METADATA."],"exampleFix":"// before: METADATA file missing 'Name' header\nMetadata-Version: 2.1\nVersion: 1.0\n// after\nMetadata-Version: 2.1\nName: mypkg\nVersion: 1.0","handlingStrategy":"try-catch","validationCode":"// Before relying on a dist's name, sanity-check the METADATA 'Name' field:\nfrom pip._internal.metadata.importlib._compat import get_dist_canonical_name\nimport importlib.metadata\nfor d in importlib.metadata.distributions():\n    if not d.metadata.get('Name'):\n        print('suspicious dist with no Name:', d)","typeGuard":null,"tryCatchPattern":"from pip._internal.metadata.importlib._compat import BadMetadata\ntry:\n    name = get_dist_canonical_name(dist)\nexcept BadMetadata as e:\n    if \"invalid metadata entry 'name'\" in e.reason:\n        # skip or reinstall the broken dist\n        ...","preventionTips":["Always include a valid 'Name' field in your package's METADATA.","Periodically audit installed distributions for missing metadata fields.","Reinstall packages reported by pip as having bad metadata."],"tags":["metadata","importlib","bad-metadata","name"],"backgroundTag":null,"analyzedSha":"f399c3718970b1b0e2478dac5296eb62679a9b86","analyzedAt":"2026-08-08T23:01:42.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}