{"record":{"id":"2c6aade7a5c376fc","repo":"keras-team/keras","slug":"layer-integerlookup-requires-tensorflow-install-i","errorCode":null,"errorMessage":"Layer IntegerLookup requires TensorFlow. Install it via `pip install tensorflow`.","messagePattern":"Layer IntegerLookup requires TensorFlow\\. Install it via `pip install tensorflow`\\.","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"critical","filePath":"keras/src/layers/preprocessing/integer_lookup.py","lineNumber":354,"sourceCode":"        self,\n        max_tokens=None,\n        num_oov_indices=1,\n        mask_token=None,\n        oov_token=-1,\n        vocabulary=None,\n        vocabulary_dtype=\"int64\",\n        idf_weights=None,\n        invert=False,\n        output_mode=\"int\",\n        sparse=False,\n        pad_to_max_tokens=False,\n        oov_method=\"floormod\",\n        salt=None,\n        name=None,\n        **kwargs,\n    ):\n        if not tf.available:\n            raise ImportError(\n                \"Layer IntegerLookup requires TensorFlow. \"\n                \"Install it via `pip install tensorflow`.\"\n            )\n        if max_tokens is not None and max_tokens <= 1:\n            raise ValueError(\n                \"If `max_tokens` is set for `IntegerLookup`, it must be \"\n                f\"greater than 1. Received: max_tokens={max_tokens}\"\n            )\n        if num_oov_indices < 0:\n            raise ValueError(\n                \"The value of `num_oov_indices` argument for `IntegerLookup` \"\n                \"must >= 0. Received: num_oov_indices=\"\n                f\"{num_oov_indices}\"\n            )\n        if sparse and backend.backend() != \"tensorflow\":\n            raise ValueError(\n                \"`sparse=True` can only be used with the TensorFlow backend.\"\n            )","sourceCodeStart":336,"sourceCodeEnd":372,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/layers/preprocessing/integer_lookup.py#L336-L372","documentation":"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.","triggerScenarios":"Constructing keras.layers.IntegerLookup() in a Keras 3 environment (jax, torch, or numpy backend) where the tensorflow package is absent.","commonSituations":"Running multi-backend Keras without tensorflow installed; slim CI images that install only keras+jax; migrating a TF script to the torch backend.","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"],"exampleFix":"// before: ImportError with jax backend, no tf\nlayer = keras.layers.IntegerLookup()\n// after\n// pip install tensorflow-cpu\nlayer = keras.layers.IntegerLookup()","handlingStrategy":"validation","validationCode":"try:\n    import tensorflow  # noqa\n    tf_ok = True\nexcept ImportError:\n    tf_ok = False\nif not tf_ok:\n    raise ImportError('IntegerLookup needs tensorflow: pip install tensorflow-cpu')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["keras","dependency","tensorflow","import-error"],"backgroundTag":"missing-dependency","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}