{"record":{"id":"3d9a9368af65b6f7","repo":"jax-ml/jax","slug":"module-package-name-has-no-attribute-name","errorCode":null,"errorMessage":"module '{package_name}' has no attribute '{name}'","messagePattern":"module '(.+?)' has no attribute '(.+?)'","errorType":"validation","errorClass":"AttributeError","httpStatus":null,"severity":"error","filePath":"jax/_src/lazy_loader.py","lineNumber":52,"sourceCode":"\n  Raises:\n    RuntimeError: If the ``__name__`` of the caller cannot be determined.\n  \"\"\"\n  owner_name = sys._getframe(1).f_globals.get(\"__name__\")\n  if owner_name is None:\n    raise RuntimeError(\"Cannot determine the ``__name__`` of the caller.\")\n\n  __all__ = list(submodules)\n\n  def __getattr__(name: str) -> Any:\n    if name in submodules:\n      value = importlib.import_module(f\"{package_name}.{name}\")\n      # Update module-level globals to avoid calling ``__getattr__`` again\n      # for this ``name``.\n      assert owner_name is not None  # pyrefly#40\n      setattr(sys.modules[owner_name], name, value)\n      return value\n    raise AttributeError(f\"module '{package_name}' has no attribute '{name}'\")\n\n  def __dir__() -> list[str]:\n    return __all__\n\n  return __getattr__, __dir__, __all__\n","sourceCodeStart":34,"sourceCodeEnd":58,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/lazy_loader.py#L34-L58","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"# before\nfrom jax.lib import xla_bridge  # typo / renamed\n\n# after\nimport jax\nclient = jax.lib.xla_client.get_default_client()","handlingStrategy":"fallback","validationCode":"import jax.lib\nname = 'xla_client'\nhas = name in dir(jax.lib)","typeGuard":"def has_attr(pkg, name):\n    return name in dir(pkg)","tryCatchPattern":"try:\n    obj = getattr(jax.lib, name)\nexcept AttributeError:\n    obj = None  # handle version without this submodule","preventionTips":["Prefer public jax.* APIs over jax.lib internals","Use getattr with default for version-optional attributes","Pin JAX version in dependencies"],"tags":["jax","lazy-loading","attributeerror","module-structure"],"backgroundTag":"module-has-no-attribute","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}