Error on tensorflow cannot import name 'export_saved_model'

Viewed 22782

I keep getting this error when importing tensorflow as tf with the below error text:

ImportError: cannot import name 'export_saved_model' from 'tensorflow.python.keras.saving.saved_model'

Code used is simply:

import tensorflow as tf

I have done:

  1. uninstalled and installed tensorflow through pip and condo via anaconda cmd prompt
  2. Restarted and cleared outputs from kernel, closing the jupyternotebook and restarting my computer

Code used for tensorflow unstallation:

  1. pip uninstall tensorflow or
  2. conda uninstall -y tensorflow

Code used for tensorflow installation:

  1. pip install tensorflow or
  2. conda install tensorflow

I can't seem to figure why it keeps saying:

"ImportError: cannot import name 'export_saved_model' from 'tensorflow.python.keras.saving.saved_model'"

3 Answers

Uninstalling and install again worked for me.

conda activate tf
pip uninstall -y tensorflow-gpu
pip install tensorflow-gpu

However, am still looking for the cause of this error. It was working just a few minutes ago but suddenly I have faced this error.

I tried uninstalling several times but it didn't work. Finally i got the solution.

Uninstall tensorflow using pip and conda Uninstall Keras also

conda uninstall -y tensorflow
pip uninstall tensorflow
pip uninstall keras

Now open the anaconda prompt, install tensorflow again

conda create -n tf tensorflow
conda activate tf

I think the issue was due to library dependencies with older versions of tensorflow. Above procedure worked for me .

The error went away when I restarted my jupyter notebook and restarted my kernel.

Related