Modulenotfounderror No Module Named ‘keras.utils.vis_utils’

In this Tensorflow tutorial, I will explain how to solve Modulenotfounderror No Module Named ‘keras.utils.vis_utils’.

There have been many changes in the Keras and Tensorflow frameworks in recent years. How we use the function or module has also changed.

I have a project, and when I upgraded Keras and TensorFlow to the latest version, I ran the project.

I got an error Modulenotfounderror No Module Named ‘keras.utils.vis_utils’ or in TensorFlow Modulenotfounderror No Module Named ‘tensorflow.keras.utils.vis_utils’.

So, in this tensorflow tutorial, I will show how to resolve these errors. Whether using the Keras framework or tensorflow, this tutorial is suitable for both developers.

Let’s begin,

Modulenotfounderror No Module Named ‘keras.utils.vis_utils’

The error means you are trying to use the keras.utils.vis_utils module from Keras, but it doesn’t exist.

For example, using the code below, let’s import the plot_model from the keras.utils.vis_utils.

from keras.utils.vis_utils import plot_model
Modulenotfounderror No Module Named 'keras.utils.vis_utils'

You get the ‘ModuleNotFoundError: No module named ‘keras.utils.vis_utils” error.

Firstly, I suggest installing the latest version of Keras in your system or environment to fix this error.

!pip install keras

Secondly, import the plot_model from the keras.utils, don’t use like keras.utils.vis_utils.

from keras.utils import plot_model

print(plot_model)
Solution to Modulenotfounderror No Module Named 'keras.utils.vis_utils'

When you import the plot_model from the keras.utils instead of keras.utils.vis_utils, it doesn’t show any error.

This is the right way to use the keras.utils module.

Modulenotfounderror No Module Named ‘tensorflow.keras.utils.vis_utils’

If you are trying to use the module tensorflow.keras.utils.vis_utils, you get the error Modulenotfounderror No Module Named ‘tensorflow.keras.utils.vis_utils’.

Let me show you one way that error can occur.

from tensorflow.keras.utils.vis_utils import plot_model
Modulenotfounderror No Module Named 'tensorflow.keras.utils.vis_utils'

The reason for this error is that the path you are using to import ‘vis_utils’ is incorrect, either due to a typo or a misunderstanding of the module location, or maybe your location has been moved to the new version of TensorFlow.

READ:  BMI Calculator Using Python Tkinter [Complete Example]

Here is the solution: import the plot_model from the tensorflow.keras.utils, not from tensorflow.keras.utils.vis_utils, as shown below.

from tensorflow.keras.utils import plot_model

print(plot_model)
Solution to Modulenotfounderror No Module Named 'tensorflow.keras.utils.vis_utils'

As you can see, the error disappears, or above is the correct way to import the function plot_model from module tensorflow.keras.utils.

In the recent version of TensorFlow, the vis_utils don’t exist anymore.

I want to suggest that you always work on the latest version of Keras and the tensorflow framework.

Look for official documentation that any module has depreciated or not, and if depreciated, then how to use them or what other new function or module is in place of depreciated function or module.

Conclusion

You learned how to fix the errors Modulenotfounderror No Module Named ‘keras.utils.vis_utils’ in Keras or Modulenotfounderror No Module Named ‘tensorflow.keras.utils.vis_utils’ in TensorFlow.

So, you learned you need to use the module keras.utils, not keras.utils.vis_utils of Keras and Tensorflow framework.

You may like to read: