{"record":{"id":"1dc423507e660cb1","repo":"pypa/pip","slug":"invalid-installed-package-1dc423","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/factory.py","lineNumber":299,"sourceCode":"\n        def _get_installed_candidate() -> Candidate | None:\n            \"\"\"Get the candidate for the currently-installed version.\"\"\"\n            # If --force-reinstall is set, we want the version from the index\n            # instead, so we \"pretend\" there is nothing installed.\n            if self._force_reinstall:\n                return None\n            try:\n                installed_dist = self._installed_dists[name]\n            except KeyError:\n                return None\n\n            try:\n                # Don't use the installed distribution if its version\n                # does not fit the current dependency graph.\n                if not specifier.contains(installed_dist.version, prereleases=True):\n                    return None\n            except InvalidVersion as e:\n                raise InvalidInstalledPackage(dist=installed_dist, invalid_exc=e)\n\n            candidate = self._make_candidate_from_dist(\n                dist=installed_dist,\n                extras=extras,\n                template=template,\n            )\n            # The candidate is a known incompatibility. Don't use it.\n            if id(candidate) in incompatible_ids:\n                return None\n            return candidate\n\n        def iter_index_candidate_infos() -> Iterator[IndexCandidateInfo]:\n            result = self._finder.find_best_candidate(\n                project_name=name,\n                specifier=specifier,\n                hashes=hashes,\n            )\n            icans = result.applicable_candidates","sourceCodeStart":281,"sourceCodeEnd":317,"githubUrl":"https://github.com/pypa/pip/blob/f399c3718970b1b0e2478dac5296eb62679a9b86/src/pip/_internal/resolution/resolvelib/factory.py#L281-L317","documentation":"In Factory._make_requirement_from_install_req (factory.py:293-299), when checking whether the installed version satisfies the specifier, specifier.contains() can raise InvalidVersion if the installed dist's version string isn't PEP 440 compliant. pip wraps this as InvalidInstalledPackage (code invalid-installed-package, invalid_type='version'). Pip 24.1+ enforces strict PEP 440 parsing.","triggerScenarios":"An installed package has a version string that doesn't conform to PEP 440 (e.g. '1.0-dev-snapshot'); the resolvelib factory tries to compare it against a specifier and InvalidVersion is raised.","commonSituations":"Packages with legacy/custom version schemes installed by older pip; upgrading pip to 24.1+ surfaces previously-tolerated bad versions.","solutions":["Uninstall the package with the malformed version.","Reinstall a version of the package that uses a PEP 440 compliant version string.","Temporarily pin pip below 24.1 while migrating away from the bad package."],"exampleFix":"# before\npip install dep   # fails: installed badpkg version '1.0x' is invalid\n# after\npip uninstall badpkg && pip install badpkg==1.0 && pip install dep","handlingStrategy":"validation","validationCode":"# Scan installed packages for non-PEP 440 versions before resolving.\nimport importlib.metadata as md\nfrom packaging.version import InvalidVersion, parse\nfor dist in md.distributions():\n    try:\n        parse(dist.version)\n    except InvalidVersion:\n        print(f\"INVALID version {dist.version!r} for {dist.metadata['Name']}; uninstall before proceeding\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use PEP 440 compliant version strings in all your packages.","Re-audit installed envs after upgrading pip to 24.1+.","Uninstall packages with non-compliant versions proactively."],"tags":["installed-package","invalid-version","pep440"],"backgroundTag":null,"analyzedSha":"f399c3718970b1b0e2478dac5296eb62679a9b86","analyzedAt":"2026-08-08T23:01:42.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}