{"record":{"id":"bb186ec2830857ca","repo":"pypa/pip","slug":"invalid-installed-package","errorCode":"invalid-installed-package","errorMessage":"Cannot process installed package {dist} in {installed_location!r} because it has an invalid {invalid_type}:\n{invalid_exc.args[0]}","messagePattern":"Cannot process installed package (.+?) in (.+?) because it has an invalid (.+?):\n(.+?)","errorType":"exception","errorClass":"InvalidInstalledPackage","httpStatus":null,"severity":"error","filePath":"src/pip/_internal/resolution/resolvelib/candidates.py","lineNumber":428,"sourceCode":"            self._version = self.dist.version\n        return self._version\n\n    @property\n    def is_editable(self) -> bool:\n        return self.dist.editable\n\n    def format_for_error(self) -> str:\n        return f\"{self.name} {self.version} (Installed)\"\n\n    def iter_dependencies(self, with_requires: bool) -> Iterable[Requirement | None]:\n        if not with_requires:\n            return\n\n        try:\n            for r in self.dist.iter_dependencies():\n                yield from self._factory.make_requirements_from_spec(str(r), self._ireq)\n        except InvalidRequirement as exc:\n            raise InvalidInstalledPackage(dist=self.dist, invalid_exc=exc) from None\n\n    def get_install_requirement(self) -> InstallRequirement | None:\n        return None\n\n\nclass ExtrasCandidate(Candidate):\n    \"\"\"A candidate that has 'extras', indicating additional dependencies.\n\n    Requirements can be for a project with dependencies, something like\n    foo[extra].  The extras don't affect the project/version being installed\n    directly, but indicate that we need additional dependencies. We model that\n    by having an artificial ExtrasCandidate that wraps the \"base\" candidate.\n\n    The ExtrasCandidate differs from the base in the following ways:\n\n    1. It has a unique name, of the form foo[extra]. This causes the resolver\n       to treat it as a separate node in the dependency graph.\n    2. When we're getting the candidate's dependencies,","sourceCodeStart":410,"sourceCodeEnd":446,"githubUrl":"https://github.com/pypa/pip/blob/f399c3718970b1b0e2478dac5296eb62679a9b86/src/pip/_internal/resolution/resolvelib/candidates.py#L410-L446","documentation":"AlreadyInstalledCandidate.iter_dependencies (candidates.py:424-428) parses the installed distribution's Requires-Dist; if a dependency string raises InvalidRequirement, pip raises InvalidInstalledPackage (code invalid-installed-package, invalid_type='requirement'). Since pip 24.1, installed packages with invalid dependency metadata can no longer be processed by the resolver.","triggerScenarios":"An already-installed package has a Requires-Dist entry that violates PEP 508; pip 24.1+ encounters it during dependency resolution and refuses to use the installed copy.","commonSituations":"Old packages installed by a prior pip version that tolerated malformed deps; upgrading pip to 24.1+ suddenly rejects them; vendor-pinned legacy packages.","solutions":["Uninstall the offending package so the resolver uses a fresh candidate.","Reinstall a version of the package whose metadata is PEP 508 compliant.","Temporarily pin pip below 24.1 while you remediate the bad package."],"exampleFix":"# before\npip install otherpkg   # fails because installed badpkg has invalid Requires-Dist\n# after\npip uninstall badpkg && pip install badpkg==<fixed-version> && pip install otherpkg","handlingStrategy":"validation","validationCode":"# Scan installed packages for invalid Requires-Dist before resolving.\nimport importlib.metadata as md\nfrom packaging.requirements import Requirement, InvalidRequirement\nbad = []\nfor dist in md.distributions():\n    for req in (dist.requires or []):\n        try:\n            Requirement(req)\n        except InvalidRequirement:\n            bad.append((dist.metadata[\"Name\"], req))\nif bad:\n    print(\"Packages with invalid Requires-Dist (uninstall before resolving):\", bad)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Audit installed packages after upgrading pip to 24.1+.","Uninstall packages with malformed metadata rather than leaving them.","Pin pip below 24.1 only as a temporary migration aid."],"tags":["installed-package","invalid-requirement","metadata"],"backgroundTag":null,"analyzedSha":"f399c3718970b1b0e2478dac5296eb62679a9b86","analyzedAt":"2026-08-08T23:01:42.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}