pypa/pip · error · NotImplementedError

Can't perform this operation for loaders without…

Error message

Can't perform this operation for loaders without 'get_data()'

What it means

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.

Solutions

  1. Use a loader that implements get_data(), or bundle resources as real files accessible on the filesystem.
  2. Switch to importlib.resources which uses a broader adapter set (Traversable/Loader protocol).
  3. For frozen apps, configure the freezer to extract resources to disk so a DefaultProvider can read them.

Example fix

// before
# loader has no get_data -> NotImplementedError
data = resource_string('mypkg', 'data.bin')
// after
import importlib.resources
data = importlib.resources.files('mypkg').joinpath('data.bin').read_bytes()
Defensive patterns

Strategy: try-catch

Validate before calling

loader = getattr(module, '__loader__', None)
if loader is None or not hasattr(loader, 'get_data'):
    raise NotImplementedError('loader lacks get_data; use importlib.resources')

Type guard

def loader_has_get_data(module) -> bool:
    loader = getattr(module, '__loader__', None)
    return loader is not None and hasattr(loader, 'get_data')

Try / catch

try:
    provider._get(path)
except NotImplementedError:
    # fallback: importlib.resources or raw file read

Prevention

When it happens

Trigger: 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.

Common situations: Frozen/embedded Python (PyInstaller, cx_Freeze) where loaders don't implement get_data; built-in modules; custom minimal import hooks.

Related errors


AI-assisted analysis of pypa/pip@f399c37189 (2026-08-08). Data as JSON: /api/errors/8580c8e0abc13b6c. Report an issue: GitHub.

Appendix: source

Thrown at src/pip/_vendor/pkg_resources/__init__.py:1831

        msg = "Use of .. or absolute path in a resource path is not allowed."

        # Aggressively disallow Windows absolute paths
        if (path.startswith("\\") or ntpath.isabs(path)) and not posixpath.isabs(path):
            raise ValueError(msg)

        # for compatibility, warn; in future
        # raise ValueError(msg)
        issue_warning(
            msg[:-1] + " and will raise exceptions in a future release.",
            DeprecationWarning,
        )

    def _get(self, path) -> bytes:
        if hasattr(self.loader, 'get_data') and self.loader:
            # Already checked get_data exists
            return self.loader.get_data(path)  # type: ignore[attr-defined]
        raise NotImplementedError(
            "Can't perform this operation for loaders without 'get_data()'"
        )


register_loader_type(object, NullProvider)


def _parents(path):
    """
    yield all parents of path including path
    """
    last = None
    while path != last:
        yield path
        last = path
        path, _ = os.path.split(path)

View on GitHub (pinned to f399c37189)