importerror: cannot import name get_config from tensorflow.python.eager.context

importerror_ cannot import name get_config from tensorflow.python.eager.context

Hardly, and most importantlyimporterror: cannot import name get_config from tensorflow.python.eager.context error occurs because of incompatibility of keras module. Actually keras is itself a standalone deeplearning library. While  Tensorflow 2.x + version maintains keras subpackage implicitly. This makes tensorflow deeplearning framework more developer friendly.

Most importantly, The tensorflow 1.x version family was bit difficult in syntax. At the same time keras was high level library. The advantage of Tensorflow over keras was more control in deep neural layers and respective session variables.

importerror: cannot import name get_config from tensorflow.python.eager.context ( Root Cause ) –

Moreover,  many developer use the Tensorflow 2.0 + version.  But they import keras ( explicitly) only. This make version incompatibility in some case if internal version are not up to the mark. Lets make this more clear please go though this simple syntax –

import tensorflow as tf
from tensorflow.keras import datasets, layers, models
from keras.preprocessing import image
from keras_preprocessing.image import ImageDataGenerator 
from tensorflow.keras.preprocessing import image_dataset_from_directory

We are actually getting error at this line.

from keras.preprocessing import image

However, the above line creates this error.


importerror: cannot import name get_config from tensorflow.python.eager.context ( Ways to Fix) –

The best way for any incompatibility issue is to upgrade submodule. Firstly, we will update the modules.

Solution 1:

Here is the command for the upgrading tensorflow module.

pip install --upgrade tensorflow
pip install --upgrade tensorflow-gpu



Solution 2 :

Replace the import package from –

from keras.preprocessing import image

Please use this import statement.

from tensorflow.keras.preprocessing import image

The idea here is to use Keras subpackage in the place of Keras package.


Solution 3:

Thirdly, and most importantly, If we are using keras module in the place of tensorflow then we have to update the keras module. Actually keeping version 2.3.1 + version is advisable.

pip install keras==2.3.1
pip install git+

Conclusion –

Firstly, Most of the import error occurs just because of the absence of the respective package or incompatibility of the internal packages. Moreover,  If you understand the basics, It will help you to fix it in other contexts too. In conclusion, There are a couple of similar errors, Please go through them –

Solution (ImportError: Could not find ‘nvcuda.dll’ TensorFlow : Step by Step Fix)

How to resolve importerror no module named tensorflow error in python?

Importerror cannot import name unrewindablebodyerror : Best Tricks to Fix

Importerror cannot import name mongoclient from pymongo : Resolve it


tensorflow component
tensorflow component

The above issues are sub package import error related.


Data Science Learner Team

Join our list

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.

Thank you for signup. A Confirmation Email has been sent to your Email Address.

Something went wrong.

Meet Abhishek ( Chief Editor) , a data scientist with major expertise in NLP and Text Analytics. He has worked on various projects involving text data and have been able to achieve great results. He is currently manages, where he and his team share knowledge and help others learn more about data science.
Thank you For sharing.We appreciate your support. Don't Forget to LIKE and FOLLOW our SITE to keep UPDATED with Data Science Learner