Home > Enterprise >  and ModuleNotFoundError: No module named 'tensorflow.keras'
and ModuleNotFoundError: No module named 'tensorflow.keras'

Time:01-02

I have installed TensorFlow with Anaconda but it shows an error.

I have the following versions:

Python                    3.9.13
keras                     2.11.0
tensorflow                2.11.0
tensorflow-estimator      2.11.0
tensorflow-gpu            2.10.1
tensorboard               2.11.0

This is the error I get:

ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
tensorflow-gpu 2.10.1 requires keras<2.11,>=2.10.0, but you have keras 2.11.0 which is incompatible.
tensorflow-gpu 2.10.1 requires tensorboard<2.11,>=2.10, but you have tensorboard 2.11.0 which is incompatible.
tensorflow-gpu 2.10.1 requires tensorflow-estimator<2.11,>=2.10.0, but you have tensorflow-estimator 2.11.0 which is incompatible.

Additionally, I get this error when I run

from tensorflow.keras.layers import TextVectorization

This is the error:

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_6684\2805265792.py in <module>
----> 1 from tensorflow.keras.layers import TextVectorization

ModuleNotFoundError: No module named 'tensorflow.keras'

I have tried the following:

pip install --user --upgrade tensorflow
pip install keras==2.11
pip install tensorflow-estimator==2.11
pip install tensorboard==2.11

But nothing works.

CodePudding user response:

Regarding the first error, I think you just need to install the compatible versions:

pip install keras==2.10.0 tensorboard==2.10 tensorflow-estimator==2.10.0

Regarding the second error, have you tried to do:

from keras.layers import TextVectorization

instead of using tensorflow.keras?

(Of course you have to install keras with pip install keras first)

CodePudding user response:

Well I it got it to work,

All it took was to remove all tensorflow files and keras from the Anaconda3

  1. `pip list'

  2. Then using 'pip uninstall 'file_name''

  3. Then reinstalling tensorflow, pip install tensorflow tensorflow-gpu

And the second error fixed itself after the reinstallation.

  • Related