ModuleNotFoundError: No module named 'keras' when using tensorflow 2.6

Viewed 2959

I created a new conda env with

conda create --name tf tensorflow=2.6

and tried to compile

import tensorflow as tf
model = tf.keras.models.Sequential()

resulting in ModuleNotFoundError: No module named 'keras'

conda install keras

doesn't change anything. I could go with

from tensorflow.keras.models import Sequential
model = Sequential()

but when I pip install tensorflow-addons and

from tensorflow_addons.seq2seq.sampler import TrainingSampler

I end up with the same error

uninstalling tensorflow, installing just keras and trying

from keras.models import Sequential
model = Sequential()

results in the same error

my versions are

tensorflow = 2.6
keras = 2.6
tensorflow-adons = 0.14
1 Answers

What turned out is that I had both keras and keras nightly installed, the problem got resolved after uninstalling keras-nightly. If anyone encounters this check your conda list and pip list for duplicate keras installations

Related