jax-ml/jax · error · AttributeError
module '{package_name}' has no attribute '{name}'
Error message
module '{package_name}' has no attribute '{name}' What it means
AttributeError from the PEP 562 __getattr__ installed by lazy_loader.attach: the requested attribute is not one of the declared lazy submodules of the package, so after failing the submodule lookup it raises. This is the standard 'module has no attribute' error for lazily loaded JAX subpackages like jax.lib or jax.experimental.
Source
Thrown at jax/_src/lazy_loader.py:52
Raises:
RuntimeError: If the ``__name__`` of the caller cannot be determined.
"""
owner_name = sys._getframe(1).f_globals.get("__name__")
if owner_name is None:
raise RuntimeError("Cannot determine the ``__name__`` of the caller.")
__all__ = list(submodules)
def __getattr__(name: str) -> Any:
if name in submodules:
value = importlib.import_module(f"{package_name}.{name}")
# Update module-level globals to avoid calling ``__getattr__`` again
# for this ``name``.
assert owner_name is not None # pyrefly#40
setattr(sys.modules[owner_name], name, value)
return value
raise AttributeError(f"module '{package_name}' has no attribute '{name}'")
def __dir__() -> list[str]:
return __all__
return __getattr__, __dir__, __all__
View on GitHub (pinned to 1e1c6a8fc0)
Solutions
- Check the attribute spelling against the JAX version's module list (dir(jax.lib))
- Import the public API instead (e.g. jax.Array, jax.device_get) rather than jax.lib internals
- Pin or match the JAX version your dependency was written for
- Use getattr(module, name, None) if the attribute is optional across versions
Example fix
# before from jax.lib import xla_bridge # typo / renamed # after import jax client = jax.lib.xla_client.get_default_client()
Defensive patterns
Strategy: fallback
Validate before calling
import jax.lib name = 'xla_client' has = name in dir(jax.lib)
Type guard
def has_attr(pkg, name):
return name in dir(pkg) Try / catch
try:
obj = getattr(jax.lib, name)
except AttributeError:
obj = None # handle version without this submodule Prevention
- Prefer public jax.* APIs over jax.lib internals
- Use getattr with default for version-optional attributes
- Pin JAX version in dependencies
When it happens
Trigger: Accessing jax.lib.<something> or similar lazily attached package where <something> is not in the attach(submodules=...) list — e.g. a typo (jax.lib.xla_client vs jax.lib.xla_extension), or a submodule removed/renamed in a JAX version.
Common situations: Upgrading JAX where internal modules were renamed (xla_client moves, jax.lib reorganization); typos in private/internal imports; code depending on jax._src or jax.lib internals that are not part of attach's submodule list.
Related errors
- {self.__class__.__name__} has no attribute {name}
- Cannot determine the ``__name__`` of the caller.
- numpy masked arrays are not supported as direct inputs to JA
- Python int {value} too large to convert to int64
- Python int {value} too large to convert to int32
AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27).
Data as JSON: /api/errors/3d9a9368af65b6f7.
Report an issue: GitHub.