{"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/d7d0d0a39494e28ec1c407bd0680e4a4d1067791/src/pip/_vendor/pkg_resources/__init__.py#L1813-L1849","documentation":"Raised as NotImplementedError by NullProvider._get(path), which reads raw bytes for a resource. _get delegates to self.loader.get_data(path); if the module's import loader does not provide a get_data() method (checked via hasattr), the operation is unsupported. get_resource_string/get_resource_stream both route through _get.","triggerScenarios":"Calling resource_string()/get_resource_string() (or get_resource_stream) on a module whose __loader__ lacks a get_data attribute — e.g. built-in/extension modules, frozen modules, or custom loaders that did not implement the PEP 302 get_data hook.","commonSituations":"Reading data files from a built-in or frozen module, or from a custom in-memory importer that omitted get_data(). The module imports fine but pkg_resources cannot fetch its resource bytes.","solutions":["Check loader capability first: `if hasattr(module.__loader__, 'get_data'): pkg_resources.resource_string(...)`.","For built-in/frozen modules, bundle data differently (e.g. importlib.resources with a compatible loader, or ship data as a Python literal) since the loader cannot serve arbitrary bytes.","Register a custom provider subclass that overrides _get to supply bytes from your own source."],"exampleFix":"// before\ndata = pkg_resources.resource_string('mymod', 'data.bin')  # NotImplementedError\n\n// after\nimport mymod\nif hasattr(getattr(mymod, '__loader__', None), 'get_data'):\n    data = pkg_resources.resource_string('mymod', 'data.bin')\nelse:\n    data = b''  # or load from an alternative source","handlingStrategy":"validation","validationCode":"import pkg_resources\n\ndef loader_supports_get_data(module):\n    loader = getattr(module, '__loader__', None)\n    return loader is not None and hasattr(loader, 'get_data')\n\ndef safe_resource_string(module, name):\n    if loader_supports_get_data(module):\n        return pkg_resources.resource_string(module.__name__, name)\n    raise NotImplementedError('loader lacks get_data()')","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    data = pkg_resources.resource_string(pkg, name)\nexcept NotImplementedError:\n    # loader cannot serve bytes; supply from alternative source\n    data = b''","preventionTips":["Check hasattr(module.__loader__, 'get_data') before reading resources.","Avoid resource_string on built-in/frozen modules; bundle data as Python literals instead.","Register a custom provider overriding _get() for loaders without get_data()."],"tags":["pkg-resources","loader","get-data","not-implemented","resources"],"analyzedSha":"d7d0d0a39494e28ec1c407bd0680e4a4d1067791","analyzedAt":"2026-08-04T20:55:04.259Z","schemaVersion":2}