For current standalone Keras, import plot_model from keras.utils, not the unavailable keras.utils.vis_utils submodule:
from keras.utils import plot_model
plot_model(model, to_file="model.png", show_shapes=True)
If your model was created with TensorFlow’s Keras API, use from tensorflow.keras.utils import plot_model instead. Keep the import in the same API family that created the model.
As an Amazon Associate I earn from qualifying purchases.
Choose the import that matches your model
The error means Python cannot find the requested keras.utils.vis_utils module in the active environment. Use the public utility import for the Keras package your code already uses; do not assume that the old submodule exists in every Keras or TensorFlow release.
| Your code builds the model with | Import to use | When this route fits |
|---|---|---|
| Standalone Keras | from keras.utils import plot_model |
The current Keras API documents keras.utils.plot_model. See Keras model plotting utilities. |
| TensorFlow Keras | from tensorflow.keras.utils import plot_model |
Use TensorFlow’s namespace when the model is built through tensorflow.keras. The Keras 2 reference documents the corresponding public legacy API as tf_keras.utils.plot_model. See Keras 2 model plotting utilities. |
For example, keep a TensorFlow Keras model and plotting utility together:
#1 Best Overall
from tensorflow.keras import Sequential
from tensorflow.keras.layers import Dense
from tensorflow.keras.utils import plot_model
model = Sequential([Dense(8, input_shape=(4,))])
plot_model(model, to_file="model.png", show_shapes=True)
Likewise, use the standalone keras namespace consistently if that is how the model was created. Keras 3 describes standalone Keras and TensorFlow’s Keras API as separate packages, not APIs to mix side by side; see the Keras 3 announcement.
Check the Python environment running your code
A correct import can still fail if the command-line Python, installed packages, and notebook kernel do not refer to the same environment. Check the Keras version from the same interpreter or notebook that produced the exception:
Rank #2
import keras
print(keras.__version__)
Keras documents this version check in its setup instructions. Before installing or changing anything, confirm that your python and pip commands target that environment. For notebooks, verify the active kernel rather than relying on a separate terminal’s package list.
Replace the old import without switching to internals
Change code that imports from keras.utils.vis_utils to the matching public import shown above. Avoid substituting a private path such as keras.src: internal namespaces are not stable interfaces, and the Keras migration guide explains the transition from TensorFlow-only Keras 2 code to multi-backend Keras 3.
If the import works but saving the diagram fails
Importing plot_model and rendering a diagram are separate steps. If the import succeeds but the call to plot_model(...) raises an ImportError, check that Graphviz and pydot are installed and visible to the same Python environment. Keras 2’s plotting reference lists missing Graphviz or pydot as an ImportError condition. Installing those rendering dependencies does not make an unavailable keras.utils.vis_utils module importable.
When to keep a legacy Keras 2 setup
If an older application depends on Keras 2 behavior, evaluate the documented compatibility options rather than changing packages blindly. Keras documents using the tf_keras package with TensorFlow and setting TF_USE_LEGACY_KERAS=1 before launching Python; the setup guide covers the configuration. Confirm the project’s TensorFlow, Keras, and dependency constraints before adopting either route. For maintained code that does not require Keras 2 compatibility, use the public import supported by the package version in use.
Quick Recap
Best Value
Quick troubleshooting checklist
- Identify whether the model is created with standalone
kerasortensorflow.keras. - Import
plot_modelfrom that same package family’s publicutilsnamespace. - Check the installed Keras version in the exact interpreter or notebook kernel raising the error.
- If only diagram rendering fails, investigate Graphviz and pydot separately from the import error.
- Use the legacy Keras 2 options only when compatibility requirements call for them.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →




