{"id":"0234bb23767b8daf","repo":"pypa/pip","slug":"invalid-metadata-version-metadata-version-value","errorCode":null,"errorMessage":"Invalid Metadata-Version: {metadata_version_value}","messagePattern":"Invalid Metadata-Version: (.+?)","errorType":"exception","errorClass":"UnsupportedWheel","httpStatus":null,"severity":"error","filePath":"src/pip/_internal/wheel_builder.py","lineNumber":114,"sourceCode":"        raise InvalidWheelFilename(\n            f\"Wheel has unexpected file name: expected {canonical_name!r}, \"\n            f\"got {w.name!r}\",\n        )\n    dist = get_wheel_distribution(FilesystemWheel(wheel_path), canonical_name)\n    dist_verstr = str(dist.version)\n    if canonicalize_version(dist_verstr) != canonicalize_version(w.version):\n        raise InvalidWheelFilename(\n            f\"Wheel has unexpected file name: expected {dist_verstr!r}, \"\n            f\"got {w.version!r}\",\n        )\n    metadata_version_value = dist.metadata_version\n    if metadata_version_value is None:\n        raise UnsupportedWheel(\"Missing Metadata-Version\")\n    try:\n        metadata_version = Version(metadata_version_value)\n    except InvalidVersion:\n        msg = f\"Invalid Metadata-Version: {metadata_version_value}\"\n        raise UnsupportedWheel(msg)\n    if metadata_version >= Version(\"1.2\") and not isinstance(dist.version, Version):\n        raise UnsupportedWheel(\n            f\"Metadata 1.2 mandates PEP 440 version, but {dist_verstr!r} is not\"\n        )\n\n\ndef _build_one(\n    req: InstallRequirement,\n    output_dir: str,\n    verify: bool,\n    editable: bool,\n) -> str | None:\n    \"\"\"Build one wheel.\n\n    :return: The filename of the built wheel, or None if the build failed.\n    \"\"\"\n    artifact = \"editable\" if editable else \"wheel\"\n    try:","sourceCodeStart":96,"sourceCodeEnd":132,"githubUrl":"https://github.com/pypa/pip/blob/d7d0d0a39494e28ec1c407bd0680e4a4d1067791/src/pip/_internal/wheel_builder.py#L96-L132","documentation":"Raised by `_verify_one` when the wheel's `Metadata-Version` field is present but is not itself a valid PEP 440 version (e.g. `2.1` parses fine, but `2.x` or `abc` does not). pip parses `Metadata-Version` with `Version(...)` and on `InvalidVersion` raises `UnsupportedWheel`. The value must be a parseable version because the spec version space is itself versioned.","triggerScenarios":"`Version(metadata_version_value)` raises `InvalidVersion` for the value read from the wheel's `METADATA`. Triggered when a backend writes a malformed `Metadata-Version` value.","commonSituations":"Hand-edited METADATA files with typos; backends writing the wrong token (e.g. `Metadata-Version: v2.1` or `Metadata-Version: latest`); tools that substitute a placeholder; corrupted download producing junk in the field.","solutions":["Inspect the wheel's `*.dist-info/METADATA` `Metadata-Version:` line and set it to a valid value such as `2.1` or `2.3`.","Rebuild with a standard backend that emits a correct `Metadata-Version`.","If the wheel was downloaded, re-download from the index to rule out corruption, and clear the pip cache (`pip cache purge`)."],"exampleFix":"# before\nMetadata-Version: v2.1   # 'v2.1' is not a valid version literal here\n\n# after\nMetadata-Version: 2.1","handlingStrategy":"validation","validationCode":"import zipfile\nfrom packaging.version import Version, InvalidVersion\n\ndef validate_wheel_metadata_version(wheel_path: str) -> None:\n    with zipfile.ZipFile(wheel_path) as z:\n        meta = next(n for n in z.namelist() if n.endswith(\".dist-info/METADATA\"))\n        text = z.read(meta).decode(\"utf-8\")\n    for line in text.splitlines():\n        if line.startswith(\"Metadata-Version:\"):\n            val = line.split(\":\", 1)[1].strip()\n            try:\n                Version(val)\n            except InvalidVersion:\n                raise ValueError(f\"Invalid Metadata-Version: {val!r}\")\n            return\n    raise ValueError(\"Missing Metadata-Version\")","typeGuard":"null","tryCatchPattern":"from pip._internal.exceptions import UnsupportedWheel\ntry:\n    _verify_one(req, wheel_path)\nexcept UnsupportedWheel as e:\n    if str(e).startswith(\"Invalid Metadata-Version\"):\n        # rewrite METADATA with a valid value and rebuild\n        ...","preventionTips":["Use a value like `2.1` or `2.3` for Metadata-Version — never `v2.1`, `latest`, etc.","Don't hand-edit METADATA fields you don't fully understand.","Rebuild from a standard backend rather than patching wheels by hand."],"tags":["wheel","packaging","metadata","versioning"],"analyzedSha":"d7d0d0a39494e28ec1c407bd0680e4a4d1067791","analyzedAt":"2026-08-04T20:55:04.259Z","schemaVersion":2}