ImportError: Failed to import pydot. You must install pydot and graphviz for ‘pydotprint’ to work error occurs when “pydot library or Graphviz is absent in your environment.” This is often encountered when visualizing models in deep learning libraries like TensorFlow and Keras.
How to fix it?
To fix the ImportError: Failed to import pydot. You must install pydot and graphviz for `pydotprint` to work error, install the below libraries one by one:
Solution 1: Using pip
pip install pydot
pip install pydotplus
pip install graphviz
After installing the required packages, you may need to restart your Jupyter kernel, IDE, or terminal session to ensure the new packages are recognized.
By following these steps, you should be able to resolve the ImportError and use the pydotprint function or other functionalities that rely on pydot and Graphviz.
Solution 2: Using conda
If you are using the conda package manager on Windows, uninstalling and reinstalling pydot + pydotplus fixed the issue on my Windows 10 machine using Anaconda 3.
conda uninstall pydot
conda uninstall pydotplus
conda uninstall graphviz
And then install the packages using these commands:
conda install pydot
conda install pydotplus
Installing pydot will also install the graphviz library.
Install Graphviz on Ubuntu
sudo apt-get install graphviz
Install Graphviz on macOS
brew install graphviz
Install Graphviz on Windows
You can download the Graphviz installer from the official Graphviz website. Follow the instructions provided on the site to install it on your system.
I hope following these steps will fix your error.
Related posts
ImportError: numpy.core.multiarray failed to import
ImportError: cannot import ‘name’ from partially initialized ‘module’
ImportError: numpy.core.multiarray failed to import

Krunal Lathiya is a seasoned Computer Science expert with over eight years in the tech industry. He boasts deep knowledge in Data Science and Machine Learning. Versed in Python, JavaScript, PHP, R, and Golang. Skilled in frameworks like Angular and React and platforms such as Node.js. His expertise spans both front-end and back-end development. His proficiency in the Python language stands as a testament to his versatility and commitment to the craft.