keras-team/keras · error · ValueError
Unable to import backend
Error message
Unable to import backend : {backend()} What it means
Sentinel error in keras/src/backend/__init__.py: the multi-backend import chain (tensorflow, jax, torch, numpy, openvino branches) encountered a backend() value with no matching branch — i.e. the configured KERAS_BACKEND is unknown or its import path is broken — so the module-level symbol table (backend ops, Variable class) cannot be populated.
Solutions
- Check the KERAS_BACKEND environment variable / ~/.keras/keras.json for a valid backend name ('tensorflow', 'jax', 'torch', 'numpy').
- Install the missing backend package (e.g. pip install 'jax[cpu]' or pip install torch).
- Reset the config with rm ~/.keras/keras.json to fall back to the default backend.
- Verify no other keras installation shadows the multi-backend package.
Defensive patterns
Strategy: fallback
When it happens
Trigger: Thrown at keras/src/backend/__init__.py:57 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25).
Data as JSON: /api/errors/91de87a228c43a5d.
Report an issue: GitHub.
Appendix: source
Thrown at keras/src/backend/__init__.py:57
from keras.src.backend.tensorflow.core import Variable as BackendVariable
elif backend() == "jax":
from keras.src.backend.jax import * # noqa: F403
from keras.src.backend.jax.core import Variable as BackendVariable
elif backend() == "torch":
from keras.src.backend.torch import * # noqa: F403
from keras.src.backend.torch.core import Variable as BackendVariable
elif backend() == "numpy":
from keras.src.backend.numpy import * # noqa: F403
from keras.src.backend.numpy.core import Variable as BackendVariable
distribution_lib = None
elif backend() == "openvino":
from keras.src.backend.openvino import * # noqa: F403
from keras.src.backend.openvino.core import Variable as BackendVariable
distribution_lib = None
else:
raise ValueError(f"Unable to import backend : {backend()}")
@keras_export("keras.Variable")
class Variable(BackendVariable): # noqa: F811
pass
backend_name_scope = name_scope # noqa: F405
@keras_export("keras.name_scope")
class name_scope(backend_name_scope):
pass
@keras_export("keras.device")
def device(device_name):
"""Context manager for backend-agnostic device placement.View on GitHub (pinned to 7a34a03db6)