{"record":{"id":"3f60a3677322b2a4","repo":"pypa/pip","slug":"requested-self-ireq-has-invalid-metadata-self","errorCode":null,"errorMessage":"Requested {self.ireq} has invalid metadata: {self.error}","messagePattern":"Requested (.+?) has invalid metadata: (.+?)","errorType":"exception","errorClass":"MetadataInvalid","httpStatus":null,"severity":"error","filePath":"src/pip/_internal/resolution/resolvelib/candidates.py","lineNumber":241,"sourceCode":"                self._ireq,\n                \"name\",\n                self._name,\n                dist.canonical_name,\n            )\n        if self._version is not None and self._version != dist.version:\n            raise MetadataInconsistent(\n                self._ireq,\n                \"version\",\n                str(self._version),\n                str(dist.version),\n            )\n        # check dependencies are valid\n        # TODO performance: this means we iterate the dependencies at least twice,\n        # we may want to cache parsed Requires-Dist\n        try:\n            list(dist.iter_dependencies(list(dist.iter_provided_extras())))\n        except InvalidRequirement as e:\n            raise MetadataInvalid(self._ireq, str(e))\n\n    def _prepare(self) -> BaseDistribution:\n        try:\n            dist = self._prepare_distribution()\n        except HashError as e:\n            # Provide HashError the underlying ireq that caused it. This\n            # provides context for the resulting error message to show the\n            # offending line to the user.\n            e.req = self._ireq\n            raise\n        except InstallationSubprocessError as exc:\n            if isinstance(self._ireq.comes_from, InstallRequirement):\n                request_chain = self._ireq.comes_from.from_path()\n            else:\n                request_chain = self._ireq.comes_from\n\n            if request_chain is None:\n                request_chain = \"directly requested\"","sourceCodeStart":223,"sourceCodeEnd":259,"githubUrl":"https://github.com/pypa/pip/blob/f399c3718970b1b0e2478dac5296eb62679a9b86/src/pip/_internal/resolution/resolvelib/candidates.py#L223-L259","documentation":"_check_metadata_consistency (candidates.py:238-241) parses the distribution's Requires-Dist entries via iter_dependencies; if any dependency string raises InvalidRequirement, pip wraps it as MetadataInvalid. The package's own metadata violates PEP 508 requirement syntax.","triggerScenarios":"Installing a package whose METADATA contains a malformed Requires-Dist value (invalid PEP 508 specifier syntax), detected during candidate preparation.","commonSituations":"Upstream packaging bug; a hand-edited METADATA; a very old package using non-standard dependency notation.","solutions":["Report the malformed metadata to the package maintainer.","Pin to a version of the package known to have valid metadata.","Fork/rebuild the package with corrected METADATA and install from your fixed source."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"# Validate a wheel's Requires-Dist entries parse as PEP 508 before install.\nimport zipfile, sys\nfrom packaging.requirements import Requirement, InvalidRequirement\nwhl = sys.argv[1]\nwith zipfile.ZipFile(whl) as z:\n    meta = [n for n in z.namelist() if n.endswith(\"METADATA\")][0]\n    for line in z.read(meta).decode().splitlines():\n        if line.startswith(\"Requires-Dist:\"):\n            spec = line.split(\":\", 1)[1].strip()\n            try:\n                Requirement(spec)\n            except InvalidRequirement as e:\n                print(f\"INVALID Requires-Dist in {whl}: {spec!r} ({e})\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate package metadata with twine check before publishing.","Pin to package versions with known-good metadata.","Keep packaging/setuptools current when building distributions."],"tags":["metadata","invalid-requirement","pep508"],"backgroundTag":null,"analyzedSha":"f399c3718970b1b0e2478dac5296eb62679a9b86","analyzedAt":"2026-08-08T23:01:42.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}