{"id":"869358cd5ced38a7","repo":"pypa/pip","slug":"cannot-find-module-self-backend-module-r-in-sel","errorCode":null,"errorMessage":"Cannot find module {self.backend_module!r} in {self.backend_path!r}","messagePattern":"Cannot find module (.+?) in (.+?)","errorType":"exception","errorClass":"BackendUnavailable","httpStatus":null,"severity":"critical","filePath":"src/pip/_vendor/pyproject_hooks/_in_process/_in_process.py","lineNumber":105,"sourceCode":"    \"\"\"\n\n    def __init__(self, backend_path, backend_module):\n        self.backend_path = backend_path\n        self.backend_module = backend_module\n        self.backend_parent, _, _ = backend_module.partition(\".\")\n\n    def find_spec(self, fullname, _path, _target=None):\n        if \".\" in fullname:\n            # Rely on importlib to find nested modules based on parent's path\n            return None\n\n        # Ignore other items in _path or sys.path and use backend_path instead:\n        spec = PathFinder.find_spec(fullname, path=self.backend_path)\n        if spec is None and fullname == self.backend_parent:\n            # According to the spec, the backend MUST be loaded from backend-path.\n            # Therefore, we can halt the import machinery and raise a clean error.\n            msg = f\"Cannot find module {self.backend_module!r} in {self.backend_path!r}\"\n            raise BackendUnavailable(msg)\n\n        return spec\n\n    if sys.version_info >= (3, 8):\n\n        def find_distributions(self, context=None):\n            # Delayed import: Python 3.7 does not contain importlib.metadata\n            from importlib.metadata import DistributionFinder, MetadataPathFinder\n\n            context = DistributionFinder.Context(path=self.backend_path)\n            return MetadataPathFinder.find_distributions(context=context)\n\n\ndef _supported_features():\n    \"\"\"Return the list of options features supported by the backend.\n\n    Returns a list of strings.\n    The only possible value is 'build_editable'.","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/pypa/pip/blob/d7d0d0a39494e28ec1c407bd0680e4a4d1067791/src/pip/_vendor/pyproject_hooks/_in_process/_in_process.py#L87-L123","documentation":"When a backend-path is configured, pyproject_hooks installs a _BackendPathFinder that is solely responsible for locating the backend module. If PathFinder.find_spec cannot locate the module's top-level parent within backend-path, it raises BackendUnavailable('Cannot find module {backend_module!r} in {backend_path!r}'), halting the normal import machinery to guarantee the backend is loaded only from backend-path.","triggerScenarios":"pyproject.toml declares a backend-path and a build-backend whose module is not present in any of those backend-path directories; the directory exists but the expected .py file/package is missing or differently named.","commonSituations":"Backend source moved or renamed without updating pyproject.toml; backend-path pointing at the wrong folder; module dotted path not matching the file layout (e.g. backend='my_backend' but file is my_backend/__init__.py missing).","solutions":["Confirm the backend module file/package exists directly under a backend-path directory.","Fix the build-backend module name to match the actual file/package name.","Correct the backend-path entry to the directory containing the backend.","Ensure the backend exposes the expected entry-point object after the ':' if one is specified."],"exampleFix":"# before\n[build-system]\nbuild-backend = \"my_backend\"\nbackend-path = [\"backend\"]  # backend/my_backend.py missing\n\n# after\n[build-system]\nbuild-backend = \"my_backend\"\nbackend-path = [\"src\"]  # src/my_backend.py now resolves","handlingStrategy":"validation","validationCode":"import os\nfor d in backend_path_dirs:\n    target = os.path.join(d, backend_module.split('.')[0])\n    if not (os.path.isfile(target + '.py') or os.path.isdir(target)):\n        raise FileNotFoundError(f'backend module not found under {d}')","typeGuard":null,"tryCatchPattern":"try:\n    backend = _build_backend()\nexcept BackendUnavailable as e:\n    if 'Cannot find module' in (e.message or ''):\n        log.error('backend not in backend-path %s', e.message)\n    raise","preventionTips":["Confirm the backend file/package exists under a backend-path dir.","Keep build-backend and backend-path in sync after refactors."],"tags":["pyproject-hooks","pep517","build","config","import"],"analyzedSha":"d7d0d0a39494e28ec1c407bd0680e4a4d1067791","analyzedAt":"2026-08-04T20:55:04.259Z","schemaVersion":2}