如何在 google colab 上安装 pydot 和 graphviz?

how to install pydot & graphviz on google colab?

我正在尝试在 google colab 上绘制我的模型。

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

我得到了这个错误:

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

我已经安装了 pydot-nggraphviz,但我仍然无法解决这个错误。

安装pydot,运行:

!pip install -q pydot

然后,重新启动您的 VM 以重新加载 keras,然后它应该会检测到 pydot 的存在。 (运行时菜单 -> 重新启动 运行time...)