Unable to import Keras

Earlier i was using Tensorflow GPU v2.10 (Windows 11 w/ nvidia gtx1650, cuDNN installed, Python 3.10.7) everything was working fine.

I upgraded TF to v2.14 and now i am unable to import keras and getting following error

ImportError: cannot import name “keras” from tensorflow (unknown location)

I am also getting following error while trying print(tf.__ version__)

AttributeError: module ‘tensorflow’ has no attribute ‘__ version__’

I have uninstalled TF and Keras and reinstalled it still no luck

1 Like

HI @yuvraj_kocher
You don’t show how your are trying to import keras.
Can you please try from tensorflow.python import keras?
As per as getting Tensorflow version can you try the following?

import tensorflow as tf
tf.__ version__

(without any space between underscore and “v” ; website formatting is annnoying me)

Thank you.

1 Like

I tried two ways:

  1. import tensorflow as tf
    from tensorflow import keras

this way gave the error mentioned in my og post.

  1. import keras

This gave me module not found error (module tensorflow.compat)

regarding checking version, yes i tried __ version__ (without space)

2 Likes

In my environment, I used Anaconda to install tf 2.10.0, pip was also used in the environment, but the IDE used tf 2.15.0 installed through pip. So I deleted the wrong environment and re-created a tf 2.0.0 environment, which allowed keras to be imported normally.