ImportError: Failed to import pydot. You must install pydot and graphviz for `pydotprint` to work

随声附和 提交于 2020-03-18 10:50:50

问题


I have seen similar issue but it is not solved either, so I decided to ask.

I am trying to visualize my model in keras using

from keras.utils import plot_model
plot_model(model, to_file='model.png')

First, it showed error

ImportError: Failed to import pydot. You must install pydot and graphviz for `pydotprint` to work.

Accordingly, I installed pydot and graphviz through Anaconda prompt activating my environment using

conda install -c https://conda.binstar.org/t/TOKEN/j14r pydot
conda install -c https://conda.binstar.org/t/TOKEN/j14r graphviz

Then, I closed spyder and reopened it. When I run code snippet, it is still showing the same error. What am I missing?


回答1:


Use next command to install them:

sudo apt install python-pydot python-pydot-ng graphviz 



回答2:


The following commands solved the problem for me

  1. pip install pydot
  2. pip install pydotplus
  3. sudo apt-get install graphviz



回答3:


These commands work for me. I did:

conda install -c https://conda.binstar.org/t/TOKEN/j14r pydot
conda install -c https://conda.binstar.org/t/TOKEN/j14r graphviz
sudo apt install python-pydot python-pydot-ng graphviz 



回答4:


For me, all I had to do was install graphviz and pydot:

On Python3:

pip3 install pydot-ng
pip3 install graphviz

On Python2:

pip3 install pydot-ng
pip3 install graphviz

That resolved the error for me.




回答5:


Restarting the Kernel solved the problem for me, without needing pydot-ng.




回答6:


Solution found from: https://github.com/XifengGuo/CapsNet-Keras/issues/69#issuecomment-483273641

I followed the advice of uninstalling and reinstalling pydot + pydotplus and that successfully solved the issue on my Windows 10 machine using Anaconda 3.

conda uninstall pydot
conda uninstall pydotplus
conda uninstall graphviz

then

conda install pydot
conda install pydotplus

Note: installing pydot also installed graphviz




回答7:


import tensorflow as tf
tf.keras.utils.plot_model(
    model,
    to_file='model.png',
    show_shapes=False,
    show_layer_names=True,
    rankdir='TB',
    expand_nested=False,
    dpi=96
)


来源:https://stackoverflow.com/questions/47605558/importerror-failed-to-import-pydot-you-must-install-pydot-and-graphviz-for-py

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!