keras-team/keras · critical · ImportError
Layer IntegerLookup requires TensorFlow. Install it via…
Error message
Layer IntegerLookup requires TensorFlow. Install it via `pip install tensorflow`.
What it means
IntegerLookup is implemented on top of TensorFlow ops, so it cannot be instantiated when TensorFlow is not importable. This ImportError is raised at layer construction regardless of the active Keras backend; install TensorFlow to use this layer.
Solutions
- pip install tensorflow (or tensorflow-cpu for a smaller install)
- Use a backend-neutral alternative such as a preprocessing step with keras.ops
- Verify with a construction smoke test in CI
Example fix
// before: ImportError with jax backend, no tf layer = keras.layers.IntegerLookup() // after // pip install tensorflow-cpu layer = keras.layers.IntegerLookup()
Defensive patterns
Strategy: validation
Validate before calling
try:
import tensorflow # noqa
tf_ok = True
except ImportError:
tf_ok = False
if not tf_ok:
raise ImportError('IntegerLookup needs tensorflow: pip install tensorflow-cpu') Prevention
- Add tensorflow (or tensorflow-cpu) to requirements when using TF-backed preprocessing layers
- Run a layer-construction smoke test in CI for every layer type you use
When it happens
Trigger: Constructing keras.layers.IntegerLookup() in a Keras 3 environment (jax, torch, or numpy backend) where the tensorflow package is absent.
Common situations: Running multi-backend Keras without tensorflow installed; slim CI images that install only keras+jax; migrating a TF script to the torch backend.
Understand the failure class
Background: "not installed", "pip install", "required for": how missing-dependency errors surface across open-source libraries — this error's family across 34 libraries.
Related errors
- Layer HashedCrossing requires TensorFlow. Install it via…
- Layer Hashing requires TensorFlow. Install it via `pip…
- Cannot do batch_dot on inputs with tf.shapes
- Cannot perform batch_dot over axis 0. If your inputs are…
- Expected the 2 dimensions of the `dilation_rate` argument…
AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25).
Data as JSON: /api/errors/2c6aade7a5c376fc.
Report an issue: GitHub.
Appendix: source
Thrown at keras/src/layers/preprocessing/integer_lookup.py:354
self,
max_tokens=None,
num_oov_indices=1,
mask_token=None,
oov_token=-1,
vocabulary=None,
vocabulary_dtype="int64",
idf_weights=None,
invert=False,
output_mode="int",
sparse=False,
pad_to_max_tokens=False,
oov_method="floormod",
salt=None,
name=None,
**kwargs,
):
if not tf.available:
raise ImportError(
"Layer IntegerLookup requires TensorFlow. "
"Install it via `pip install tensorflow`."
)
if max_tokens is not None and max_tokens <= 1:
raise ValueError(
"If `max_tokens` is set for `IntegerLookup`, it must be "
f"greater than 1. Received: max_tokens={max_tokens}"
)
if num_oov_indices < 0:
raise ValueError(
"The value of `num_oov_indices` argument for `IntegerLookup` "
"must >= 0. Received: num_oov_indices="
f"{num_oov_indices}"
)
if sparse and backend.backend() != "tensorflow":
raise ValueError(
"`sparse=True` can only be used with the TensorFlow backend."
)View on GitHub (pinned to 7a34a03db6)