Error: cannot import name 'StringLookup' from 'tensorflow.keras.layers.experimental.preprocessing'

Viewed 1804

I can import preprocessing:

from tensorflow.keras.layers.experimental import preprocessing

But I can't import or use any of the layers inside it:

from tensorflow.keras.layers.experimental.preprocessing import StringLookup

ImportError  Traceback (most recent call last)
<ipython-input-78-4f042fcbcc66> in <module>
----> 1 from tensorflow.keras.layers.experimental.preprocessing import StringLookup

ImportError: cannot import name 'StringLookup' from 'tensorflow.keras.layers.experimental.preprocessing' (/home/julie/miniconda3/envs/tf-gpu/lib/python3.8/site-packages/tensorflow/keras/layers/experimental/preprocessing/__init__.py)

I found several resources citing versions as the issue. My environment is running:

  • Tensorflow 2.2.0
  • Keras 2.4.3

Both were installed through conda.

2 Answers

It seems your python is python 3.9. Make sure your python version is Python 3.5–3.8. check your version by $ python3 --version.

Reinstall python 3.8 as tensorflow does not support for a higher version of python. Use the command line to install. conda install python=3.8.

The only solution that worked for me is:

pip install tensorflow==2.6.0
pip install keras==2.6.0

By bringing both tf and keras to 2.6.0

Related