{"record":{"id":"39fc0abb64fb32c9","repo":"pypa/pip","slug":"the-self-req-distribution-was-not-found-and-is","errorCode":null,"errorMessage":"The '{self.req}' distribution was not found and is required by {self.requirers_str}","messagePattern":"The '(.+?)' distribution was not found and is required by (.+?)","errorType":"exception","errorClass":"DistributionNotFound","httpStatus":null,"severity":"error","filePath":"src/pip/_vendor/pkg_resources/__init__.py","lineNumber":929,"sourceCode":"            # Find the best distribution and add it to the map\n            dist = self.by_key.get(req.key)\n            if dist is None or (dist not in req and replace_conflicting):\n                ws = self\n                if env is None:\n                    if dist is None:\n                        env = Environment(self.entries)\n                    else:\n                        # Use an empty environment and workingset to avoid\n                        # any further conflicts with the conflicting\n                        # distribution\n                        env = Environment([])\n                        ws = WorkingSet([])\n                dist = best[req.key] = env.best_match(\n                    req, ws, installer, replace_conflicting=replace_conflicting\n                )\n                if dist is None:\n                    requirers = required_by.get(req, None)\n                    raise DistributionNotFound(req, requirers)\n            to_activate.append(dist)\n        if dist not in req:\n            # Oops, the \"best\" so far conflicts with a dependency\n            dependent_req = required_by[req]\n            raise VersionConflict(dist, req).with_context(dependent_req)\n        return dist\n\n    @overload\n    def find_plugins(\n        self,\n        plugin_env: Environment,\n        full_env: Environment | None,\n        installer: _InstallerTypeT[_DistributionT],\n        fallback: bool = True,\n    ) -> tuple[list[_DistributionT], dict[Distribution, Exception]]: ...\n    @overload\n    def find_plugins(\n        self,","sourceCodeStart":911,"sourceCodeEnd":947,"githubUrl":"https://github.com/pypa/pip/blob/f399c3718970b1b0e2478dac5296eb62679a9b86/src/pip/_vendor/pkg_resources/__init__.py#L911-L947","documentation":"Raised as DistributionNotFound during WorkingSet.resolve() when a required distribution cannot be found in the working set, the search environment, or via the installer. The message lists the requirement and the requirers (the packages/applications that need it). This means the dependency is simply not installed and cannot be located.","triggerScenarios":"Calling pkg_resources.require('nonexistent-package==1.0') or working_set.resolve([...]) for a dependency that is not installed and not installable by the configured installer.","commonSituations":"A missing dependency that was never installed; a typo in a package name in requirements.txt; a dependency that is optional but required at runtime; an installer (e.g. in a frozen/offline env) that cannot fetch the package.","solutions":["Install the missing package: pip install <package-name>.","Correct any typo in the requirement string.","Ensure the package is listed in your install_requires/dependencies and that the install step ran successfully."],"exampleFix":"// before\npkg_resources.require('CustomePkg>=1.0')  # typo, not installed\n// after\npip install CustomPkg\npkg_resources.require('CustomPkg>=1.0')","handlingStrategy":"try-catch","validationCode":"# Check existence before resolving\nimport importlib.util\nif importlib.util.find_spec(pkg_name) is None:\n    raise ImportError(f'{pkg_name} is not installed')","typeGuard":null,"tryCatchPattern":"try:\n    pkg_resources.require(req_str)\nexcept DistributionNotFound as e:\n    print(e.report())\n    # offer to install e.req.project_name","preventionTips":["Validate package names against installed distributions before calling require().","Catch DistributionNotFound to give actionable 'pip install' suggestions."],"tags":["pkg-resources","missing-dependency","dependency-resolution"],"backgroundTag":null,"analyzedSha":"f399c3718970b1b0e2478dac5296eb62679a9b86","analyzedAt":"2026-08-08T23:01:42.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}