{"record":{"id":"8580c8e0abc13b6c","repo":"pypa/pip","slug":"can-t-perform-this-operation-for-loaders-without","errorCode":null,"errorMessage":"Can't perform this operation for loaders without 'get_data()'","messagePattern":"Can't perform this operation for loaders without 'get_data\\(\\)'","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"src/pip/_vendor/pkg_resources/__init__.py","lineNumber":1831,"sourceCode":"\n        msg = \"Use of .. or absolute path in a resource path is not allowed.\"\n\n        # Aggressively disallow Windows absolute paths\n        if (path.startswith(\"\\\\\") or ntpath.isabs(path)) and not posixpath.isabs(path):\n            raise ValueError(msg)\n\n        # for compatibility, warn; in future\n        # raise ValueError(msg)\n        issue_warning(\n            msg[:-1] + \" and will raise exceptions in a future release.\",\n            DeprecationWarning,\n        )\n\n    def _get(self, path) -> bytes:\n        if hasattr(self.loader, 'get_data') and self.loader:\n            # Already checked get_data exists\n            return self.loader.get_data(path)  # type: ignore[attr-defined]\n        raise NotImplementedError(\n            \"Can't perform this operation for loaders without 'get_data()'\"\n        )\n\n\nregister_loader_type(object, NullProvider)\n\n\ndef _parents(path):\n    \"\"\"\n    yield all parents of path including path\n    \"\"\"\n    last = None\n    while path != last:\n        yield path\n        last = path\n        path, _ = os.path.split(path)\n\n","sourceCodeStart":1813,"sourceCodeEnd":1849,"githubUrl":"https://github.com/pypa/pip/blob/f399c3718970b1b0e2478dac5296eb62679a9b86/src/pip/_vendor/pkg_resources/__init__.py#L1813-L1849","documentation":"Raised by NullProvider._get() when the module's loader object does not have a get_data() method. _get() is the low-level byte-reader for resources; it first checks hasattr(self.loader, 'get_data') and, if absent, raises NotImplementedError. This occurs for loaders that don't implement the PEP 302/451 get_data protocol.","triggerScenarios":"Calling a resource-reading API (resource_string, get_metadata) on a module whose __loader__ lacks get_data — e.g. certain built-in loaders, frozen-module loaders, or minimal custom loaders.","commonSituations":"Frozen/embedded Python (PyInstaller, cx_Freeze) where loaders don't implement get_data; built-in modules; custom minimal import hooks.","solutions":["Use a loader that implements get_data(), or bundle resources as real files accessible on the filesystem.","Switch to importlib.resources which uses a broader adapter set (Traversable/Loader protocol).","For frozen apps, configure the freezer to extract resources to disk so a DefaultProvider can read them."],"exampleFix":"// before\n# loader has no get_data -> NotImplementedError\ndata = resource_string('mypkg', 'data.bin')\n// after\nimport importlib.resources\ndata = importlib.resources.files('mypkg').joinpath('data.bin').read_bytes()","handlingStrategy":"try-catch","validationCode":"loader = getattr(module, '__loader__', None)\nif loader is None or not hasattr(loader, 'get_data'):\n    raise NotImplementedError('loader lacks get_data; use importlib.resources')","typeGuard":"def loader_has_get_data(module) -> bool:\n    loader = getattr(module, '__loader__', None)\n    return loader is not None and hasattr(loader, 'get_data')","tryCatchPattern":"try:\n    provider._get(path)\nexcept NotImplementedError:\n    # fallback: importlib.resources or raw file read","preventionTips":["Use importlib.resources which handles more loader types.","Ensure frozen/embedded apps expose resources as real files."],"tags":["pkg-resources","resources","loader","not-implemented"],"backgroundTag":null,"analyzedSha":"f399c3718970b1b0e2478dac5296eb62679a9b86","analyzedAt":"2026-08-08T23:01:42.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}