{"id":"0f5b069d8a8943d8","repo":"pypa/pip","slug":"requested-ireq-has-invalid-metadata-error","errorCode":null,"errorMessage":"Requested {ireq} has invalid metadata: {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/d7d0d0a39494e28ec1c407bd0680e4a4d1067791/src/pip/_internal/resolution/resolvelib/candidates.py#L223-L259","documentation":"MetadataInvalid raised when iterating the prepared distribution's dependencies raises InvalidRequirement — i.e. the artifact's METADATA contains a Requires-Dist (or similar) field that is not a valid PEP 508 requirement string. pip cannot build a dependency graph from malformed metadata, so it aborts the candidate.","triggerScenarios":"list(dist.iter_dependencies(...)) raises InvalidRequirement inside _check_metadata_consistency. Concretely: a package whose METADATA has a Requires-Dist line with bad syntax (unbalanced extras, stray characters, invalid version specifiers, non-PEP508 markers).","commonSituations":"Old packages authored before strict PEP 508 enforcement; hand-edited METADATA; a sdist whose setup(install_requires=[...]) produced a malformed entry; metadata generated by an ancient setuptools that emitted non-canonical requirement strings.","solutions":["Upgrade the offending package to a release with corrected metadata, if available.","If you own the package, fix the malformed Requires-Dist/entry and republish.","Pin to an older known-good version of the package whose metadata parses.","As a last resort, install with --no-deps and manage dependencies manually (not recommended for untrusted packages)."],"exampleFix":"# before - package metadata has: Requires-Dist: foo;extra bad[syntax]\npip install brokenpkg\n\n# after - use a release with valid metadata, or fix upstream\npip install \"brokenpkg==1.2.3\"  # release known to parse","handlingStrategy":"validation","validationCode":"from packaging.requirements import Requirement, InvalidRequirement\n\ndef validate_dist_metadata_requires(requires_dist_lines):\n    for line in requires_dist_lines:\n        try:\n            Requirement(line)\n        except InvalidRequirement as e:\n            raise ValueError(f\"invalid Requires-Dist {line!r}: {e}\") from None\n# run over a wheel's METADATA before publishing or pinning","typeGuard":null,"tryCatchPattern":"try:\n    pip_install(req)\nexcept InstallationError as e:\n    if 'invalid metadata' in str(e):\n        pin_known_good_release(req)\n    else:\n        raise","preventionTips":["Validate Requires-Dist with packaging.requirements.Requirement before publishing.","Keep setuptools/build backend current so it emits PEP 508-compliant metadata.","Run `check-wheel-contents`/`twine check` in your release CI."],"tags":["pip","resolvelib","metadata","pep508","packaging"],"analyzedSha":"d7d0d0a39494e28ec1c407bd0680e4a4d1067791","analyzedAt":"2026-08-04T20:55:04.259Z","schemaVersion":2}