pypa/pip · error · NotImplementedError
Can't perform this operation for unregistered loader type
Error message
Can't perform this operation for unregistered loader type
What it means
Raised by NullProvider._has() — a stub that always raises NotImplementedError because the base NullProvider has no knowledge of how to check file existence for an arbitrary PEP 302/451 loader. Only concrete subclasses (DefaultProvider, EggProvider, ZipProvider) override _has() with a real filesystem implementation. Hitting this means the provider in use is the un-extended base.
Solutions
- Register your loader type with pkg_resources.register_loader_type(MyLoader, DefaultProvider) so resource ops use a concrete provider.
- Ensure the module has a standard __file__-backed filesystem loader so EggProvider/DefaultProvider is selected automatically.
- Avoid pkg_resources resource APIs for custom loaders; use importlib.resources instead.
Example fix
// before
# custom loader, NullProvider._has() raises
has = provider.has_resource('data.txt')
// after
import pkg_resources
pkg_resources.register_loader_type(MyLoader, pkg_resources.DefaultProvider)
has = provider.has_resource('data.txt') Defensive patterns
Strategy: try-catch
Validate before calling
# Register loader before using resource APIs import pkg_resources pkg_resources.register_loader_type(type(module.__loader__), pkg_resources.DefaultProvider)
Try / catch
try:
provider.has_resource(name)
except NotImplementedError:
# fallback to importlib.resources or register loader Prevention
- Register custom loaders with register_loader_type().
- Migrate to importlib.resources for loader-agnostic access.
When it happens
Trigger: A resource operation (has_resource/has_metadata) routed to a NullProvider instance because the module's loader type was not registered with register_loader_type() to map it to a concrete provider like DefaultProvider.
Common situations: Using a custom import hook/loader that is not registered; a namespace package or module loaded by an unusual loader (e.g. in a frozen app, embedded interpreter) that pkg_resources does not recognize.
Related errors
- Can't perform this operation for loaders without…
- `base` parameter in `_fn` is `None`. Either override this…
- Can't change extraction path, files already extracted
- "os.rename" and "os.unlink" are not supported on this…
- resource_filename() only supported for .egg, not .zip
AI-assisted analysis of pypa/pip@f399c37189 (2026-08-08).
Data as JSON: /api/errors/62bc28b7ca8f7e65.
Report an issue: GitHub.
Appendix: source
Thrown at src/pip/_vendor/pkg_resources/__init__.py:1728
namespace['__file__'] = script_filename
if os.path.exists(script_filename):
source = _read_utf8_with_fallback(script_filename)
code = compile(source, script_filename, 'exec')
exec(code, namespace, namespace)
else:
from linecache import cache
cache[script_filename] = (
len(script_text),
0,
script_text.split('\n'),
script_filename,
)
script_code = compile(script_text, script_filename, 'exec')
exec(script_code, namespace, namespace)
def _has(self, path) -> bool:
raise NotImplementedError(
"Can't perform this operation for unregistered loader type"
)
def _isdir(self, path) -> bool:
raise NotImplementedError(
"Can't perform this operation for unregistered loader type"
)
def _listdir(self, path) -> list[str]:
raise NotImplementedError(
"Can't perform this operation for unregistered loader type"
)
def _fn(self, base: str | None, resource_name: str):
if base is None:
raise TypeError(
"`base` parameter in `_fn` is `None`. Either override this method or check the parameter first."
)View on GitHub (pinned to f399c37189)