{"record":{"id":"53499ca0fcb6f971","repo":"pypa/pip","slug":"self-dist-is-installed-but-self-req-is-require","errorCode":null,"errorMessage":"{self.dist} is installed but {self.req} is required","messagePattern":"(.+?) is installed but (.+?) is required","errorType":"exception","errorClass":"VersionConflict","httpStatus":null,"severity":"error","filePath":"src/pip/_vendor/pkg_resources/__init__.py","lineNumber":724,"sourceCode":"        If there is an active distribution for the requested project, this\n        returns it as long as it meets the version requirement specified by\n        `req`.  But, if there is an active distribution for the project and it\n        does *not* meet the `req` requirement, ``VersionConflict`` is raised.\n        If there is no active distribution for the requested project, ``None``\n        is returned.\n        \"\"\"\n        dist = self.by_key.get(req.key)\n\n        if dist is None:\n            canonical_key = self.normalized_to_canonical_keys.get(req.key)\n\n            if canonical_key is not None:\n                req.key = canonical_key\n                dist = self.by_key.get(canonical_key)\n\n        if dist is not None and dist not in req:\n            # XXX add more info\n            raise VersionConflict(dist, req)\n        return dist\n\n    def iter_entry_points(self, group: str, name: str | None = None):\n        \"\"\"Yield entry point objects from `group` matching `name`\n\n        If `name` is None, yields all entry points in `group` from all\n        distributions in the working set, otherwise only ones matching\n        both `group` and `name` are yielded (in distribution order).\n        \"\"\"\n        return (\n            entry\n            for dist in self\n            for entry in dist.get_entry_map(group).values()\n            if name is None or name == entry.name\n        )\n\n    def run_script(self, requires: str, script_name: str):\n        \"\"\"Locate distribution for `requires` and run `script_name` script\"\"\"","sourceCodeStart":706,"sourceCodeEnd":742,"githubUrl":"https://github.com/pypa/pip/blob/f399c3718970b1b0e2478dac5296eb62679a9b86/src/pip/_vendor/pkg_resources/__init__.py#L706-L742","documentation":"Raised as VersionConflict by WorkingSet.find() when a distribution for the requested project IS installed and active, but its version does not satisfy the given Requirement. The message names the installed distribution and the requirement that failed. This is a dependency-version mismatch detected against the active working set.","triggerScenarios":"Calling working_set.find(Requirement.parse('requests>=2.25')) when requests 2.20.0 is the active distribution; require('package>=X') where the installed version is older.","commonSituations":"A virtualenv with a stale or mismatched package version after a partial upgrade; pinning a higher minimum in requirements but not reinstalling; dependency conflicts surfaced when a plugin or entry point loads.","solutions":["Upgrade the conflicting package to a version satisfying the requirement: pip install 'package>=<required>'.","Loosen the requirement specifier to include the installed version, if the older version is actually acceptable.","Recreate the virtualenv from a clean requirements lock file so all versions are consistent."],"exampleFix":"// before\n# requests 2.20 installed, requirement is requests>=2.25\nworking_set.find(Requirement.parse('requests>=2.25'))\n// after\n# install a compatible version first\npip install 'requests>=2.25'\nworking_set.find(Requirement.parse('requests>=2.25'))","handlingStrategy":"try-catch","validationCode":"# Pre-check installed version before calling find/require\nimport pkg_resources\ninstalled = pkg_resources.get_distribution('requests').version\nif not Requirement.parse('requests>=2.25').specifier.contains(installed):\n    print(f'Need >=2.25, have {installed}')","typeGuard":null,"tryCatchPattern":"try:\n    working_set.find(req)\nexcept VersionConflict as e:\n    print(e.report())  # '{dist} is installed but {req} is required'","preventionTips":["Use pip install with pinned versions so the env matches your requires().","Catch VersionConflict specifically and report e.report() to users."],"tags":["pkg-resources","dependency-conflict","version-conflict"],"backgroundTag":null,"analyzedSha":"f399c3718970b1b0e2478dac5296eb62679a9b86","analyzedAt":"2026-08-08T23:01:42.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}