简体   繁体   中英

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

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.

I'm new to Tensorflow and not really understanding how these two relate. If someone could point me in the direction of what I'm missing, I'd be grateful!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM