. Advertisement .
..3..
. Advertisement .
..4..
When you try to do anything automated in the tool, the following error appears: “ImportError: cannot import name ‘get_config’ from ‘tensorflow.python.eager.context’ in Python“. Don’t worry too much. This post will support you in resolving the error with the best solution.
When Will The Error “ImportError: cannot import name ‘get_config’ from ‘tensorflow.python.eager.context’ in Python” Occur?
You received the following error when you ran your code.
ImportError: cannot import name ‘get_config’ from ‘tensorflow.python.eager.context’ in Python
In another case, your notebook was operational until today. You installed tf-nightly at the start of the colab notebook, but it now returns the following error:
ImportError Traceback (most recent call last) <ipython-input-1-589c442233c5> in <module>() 7 import tensorflow as tf 8 from tensorflow.keras import datasets, layers, models ----> 9 from keras.preprocessing import image 10 from keras_preprocessing.image import ImageDataGenerator #check underscore or not 11 from tensorflow.keras.preprocessing import image_dataset_from_directory 2 frames /usr/local/lib/python3.7/dist-packages/keras/backend.py in <module>() 35 from tensorflow.python.distribute import distribute_coordinator as dc 36 from tensorflow.python.distribute import distribute_coordinator_context as dc_context ---> 37 from tensorflow.python.eager.context import get_config 38 from tensorflow.python.framework import config 39 from keras import backend_config ImportError: cannot import name 'get_config' from 'tensorflow.python.eager.context' (/usr/local/lib/python3.7/dist-packages/tensorflow_core/python/eager/context.py)
The Effective Methods For The Error “ImportError: cannot import name ‘get_config’ from ‘tensorflow.python.eager.context’ in Python”
Choose the best option for you to solve the “ImportError: cannot import name ‘get_config’ from ‘tensorflow.python.eager.context’ in Python” error.
Solution 1: Upgrade the tensorflow
You resolved this problem by simply upgrading TensorFlow and TensorFlow GPU. You can execute the following command in your console to upgrade TensorFlow and TensorFlow GPU.
pip install --upgrade tensorflow
pip install --upgrade tensorflow-gpu
Your error must now be fixed.
Solution 2: Change import Methods
If you’re using Keras, change the import method as shown below. In place of this code.
import keras
You can use this code.
from tensorflow import keras
Use instead of if you’re using Image.
from keras.preprocessing import image
Replace the above code with the below code.
from tensorflow.keras.preprocessing import image
Solution 3: Change the import
Change the import from the following
from keras.preprocessing.image import ImageDataGenerator
to
from tensorflow.keras.preprocessing.image import ImageDataGenerator
Conclusion
Those simple approaches presented above are simple solutions to the aforementioned major error: “ImportError: cannot import name ‘get_config’ from ‘tensorflow.python.eager.context’ in Python“.
Please leave all your concerns in the comments section if you have any further questions. I wish you all an effective day with your tool.
makre sure that the version that you installed correctly, have you tried the version of Keras 2.3.1?
then, install
Just using the follow suggestion
instead of