问题
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
- pip install pydot
- pip install pydotplus
- 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