3

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
SzymonO
  • 337
  • 1
  • 13
  • try `from tensorflow.keras .models import Sequential` – Avishka Dambawinna Oct 27 '21 at 06:29
  • @AvishkaDambawinna I tried but I need to use tensorflow_addons. Read the full question – SzymonO Oct 27 '21 at 06:37
  • Please checkout these threads . https://stackoverflow.com/questions/45271344/importerror-no-module-named-keras https://www.edureka.co/community/67388/modulenotfounderror-no-module-named-keras – Tensorflow Support Nov 18 '21 at 04:47
  • I faced the same problem. I had to downgrade tensorflow to 2.5 then it worked. The only command I used is `conda create --name tf tensorflow=2.5`, no need to install anything else. – Gqqnbig Dec 18 '21 at 17:27
  • @Gqqnbig turns out that I had 2 keras versions installed, one from tensorflow and one from tensorflow nightly. Would be wise to check your `conda list` and `pip list` for duplicate keras installations – SzymonO Dec 19 '21 at 18:08

1 Answers1

0

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

SzymonO
  • 337
  • 1
  • 13