Python Keras:“运行时错误:无法导入 pydot。” 安装graphviz和pydot后
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36886711/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Keras: "RuntimeError: Failed to import pydot." after installing graphviz and pydot
提问by ishido
I'm using Anaconda Python 2.7 on windows 10
我在 Windows 10 上使用 Anaconda Python 2.7
I was planning on doing Keras visualization so (whilst spyder was open) I opened the Anaconda command prompt and pip installed graphviz and pydot. Now when I try run the following:
我计划进行 Keras 可视化,所以(当 spyder 处于打开状态时)我打开了 Anaconda 命令提示符并 pip 安装了 graphviz 和 pydot。现在,当我尝试运行以下命令时:
from keras.models import Sequential
or any sort of "from keras." , I get the error:
或任何类型的“来自 keras”。,我收到错误:
ImportError: cannot import name gof
I have uninstalled and reinstalled Keras, Graphviz and pydot. i am using the development version of theano. I cannot find a fix.
我已经卸载并重新安装了 Keras、Graphviz 和 pydot。我正在使用 theano 的开发版本。我找不到解决办法。
P.S
聚苯乙烯
If I uninstall graphviz and pydot, keras works again
如果我卸载 graphviz 和 pydot,keras 会再次工作
EDIT
编辑
After uninstalling anaconda and reinstalling it including theano, keras, graphviz and pydotI now get the following error:
卸载 anaconda 并重新安装包括 theano、keras、graphviz 和 pydot 后,我现在收到以下错误:
from keras.utils.visualize_util import plot
Using Theano backend.
Using gpu device 0: GeForce GTX 970M (CNMeM is disabled, cuDNN not available)
Traceback (most recent call last):
File "<ipython-input-1-65016ddab3cd>", line 1, in <module>
from keras.utils.visualize_util import plot
File "C:\Anaconda2\lib\site-packages\keras\utils\visualize_util.py", line 8, in <module>
raise RuntimeError('Failed to import pydot. You must install pydot'
RuntimeError: Failed to import pydot. You must install pydot and graphviz for `pydotprint` to work.
I used pip install graphviz
and pip install git+https://github.com/nlhepler/pydot.git
我用过pip install graphviz
和pip install git+https://github.com/nlhepler/pydot.git
回答by Dr. Snoopy
The error message is a bit misleading, as you can see here. The problem is that graphviz is not installed.
错误消息有点误导,你可以在这里看到。问题是没有安装graphviz。
But you mention that graphviz was installed using pip. This is also misleading, since that graphviz package is just a python wrapper, and the graphviz binarieshave to be installed separately for the python wrapper to work.
但是你提到graphviz是使用pip安装的。这也是一种误导,因为该 graphviz 包只是一个 python 包装器,并且必须单独安装graphviz 二进制文件才能使 python 包装器工作。
回答by Tom
If you are using an Anaconda environment, you'd better install pydotplus
and graphviz
via conda install
.
如果您使用的是 Anaconda 环境,则最好安装pydotplus
并graphviz
通过conda install
.
conda install graphviz
conda install pydotplus
Note:
You'd better update your Keras to the newest version (2.0.9+), it can automatically check and choose which one of pydotplus
,pydot-ng
,pydot
to be used. pydot-ng
has been unmaintained for a long time, and it only supports py3.4- and py2.7.
注意:你最好更新Keras到最新版本(2.0.9+),它可以自动检查并选择其中一个pydotplus
,pydot-ng
,pydot
使用。pydot-ng
已经很久无人维护了,只支持py3.4-和py2.7。
回答by alhanaei
I had the same problem. I am using Anaconda python on Ubuntu. but it seams that Keras uses system's python not the Anaconda python. Initially, I installed pydot and graphviz using conda. When I installed pydot and graphviz in system's python(using /usr/bin/pip install pydot) it worked fine.
我有同样的问题。我在 Ubuntu 上使用 Anaconda python。但它接缝是 Keras 使用系统的 python 而不是 Anaconda python。最初,我使用 conda 安装了 pydot 和 graphviz。当我在系统的 python(使用 /usr/bin/pip install pydot)中安装 pydot 和 graphviz 时,它运行良好。
回答by Yupei
What I did is followed.
我所做的被遵循。
import keras
import pydotplus
from keras.utils.vis_utils import model_to_dot
keras.utils.vis_utils.pydot = pydot
plot_model(your_model_name, to_file='model.png')
That's worked for me. On mac Anaconda python=3.6.8
这对我有用。在 mac Anaconda 上 python=3.6.8
回答by jok
回答by yogesh
Install graphviz by brew in osx brew install graphviz
, for ubuntu use apt-get install graphviz
, do not need to install graphviz by pip.
在 osx 中通过 brew 安装 graphviz brew install graphviz
,对于 ubuntu 使用apt-get install graphviz
,不需要通过 pip 安装 graphviz。
回答by Eka
I had similar problem with my Keras (without anaconda). I have solved my problem using this way
我的 Keras(没有 anaconda)有类似的问题。我已经用这种方式解决了我的问题
sudo pip install pydot
sudo pip install graphviz
sudo add-apt-repository ppa:gviz-adm/graphviz-dev
sudo apt-get update
sudo apt-get install graphviz-dev
回答by saneryee
For Anaconda on Mac:
对于 Mac 上的 Anaconda:
To install this package with conda run:
要使用 conda 安装此软件包,请运行:
conda install -c anaconda graphviz
conda install -c anaconda graphviz
回答by Shih-Wen Su
Install
graphviz
to the system. Download the package from here, or on Mac:brew install graphviz
Install python pydot-ng and graphviz wrapper.
pip install pydot-ng graphviz conda install -c anaconda pydot-ng #Anaconda user
Use
pydot-ng
in your codeimport pydot_ng as pydot
If Keras visualization utils still uses pydot, try to change
import pydot
toimport pydot_ng as pydot
invisualize_util.py
安装
graphviz
到系统。从这里或在 Mac 上下载软件包:brew install graphviz
安装 python pydot-ng 和 graphviz 包装器。
pip install pydot-ng graphviz conda install -c anaconda pydot-ng #Anaconda user
pydot-ng
在您的代码中使用import pydot_ng as pydot
如果Keras可视化utils的仍使用pydot,尝试改变
import pydot
,以import pydot_ng as pydot
在visualize_util.py
回答by amit pandey
1)Conda install graphviz
2)pip install graphviz
3)pip install pydot
then:
1)Conda 安装graphviz
2)pip 安装graphviz
3)pip 安装pydot
然后:
import os
os.environ["PATH"] += os.pathsep + AppData\\Local\\Continuum\\anaconda3\\envs\\tensorflow\\Library\\bin\\graphviz'
import os
os.environ["PATH"] += os.pathsep + AppData\\Local\\Continuum\\anaconda3\\envs\\tensorflow\\Library\\bin\\graphviz'