all Python 3until 3.14Removed from the standard libraryfunction
pkgutil.find_loader()
removed
Found the loader for a module by name. Removed in Python 3.14 — use importlib.util.find_spec().
Syntax
pkgutil.find_loader('json') # до 3.14
find_loader('json') answered "can this module be imported, and who will load it" without running the import. It was removed once the import system moved to module specs, where the loader is just one field of the spec. To migrate, replace pkgutil.find_loader(name) with importlib.util.find_spec(name); if you need the loader itself, take .loader from the result. For a missing module find_spec returns None just as before, so an is None check stays the same.
Examples
# Python 3.14+
import pkgutil
try:
pkgutil.find_loader
except AttributeError as e:
print(type(e).__name__) # → AttributeError
# Python 3.14+
import importlib.util
spec = importlib.util.find_spec('json')
print(type(spec.loader).__name__) # → SourceFileLoader
print(importlib.util.find_spec('no_such_module_xyz')) # → None
import pkgutil
print(type(pkgutil.find_loader('json')).__name__) # → SourceFileLoader
print(pkgutil.find_loader('no_such_module_xyz')) # → None
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy