找不到 Graphviz 的可执行文件(Python 3.4)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28312534/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 03:05:18  来源:igfitidea点击:

Graphviz's executables are not found (Python 3.4)

pythonpathgraphvizpydot

提问by Morteza R

I am running Python3.4 on Windows 7. I am trying to use the Python interface for graphviz. This is a script I intend to run:

我在 Windows 7 上运行 Python3.4。我正在尝试将 Python 接口用于 graphviz。这是我打算运行的脚本:

from graphviz import Digraph
import pydotplus

dot = Digraph(comment='The Round Table')

dot.node('A', 'King Arthur')
dot.node('B', 'Sir Bedevere the Wise')
dot.node('L', 'Sir Lancelot the Brave')
dot.edges(['AB', 'AL'])
dot.edge('B', 'L', constraint='false')

print(dot.source)
dot.render('test-output/round-table.gv', view=True)

I get the following error at runtime:

我在运行时收到以下错误:

RuntimeError: failed to execute ['dot', '-Tpdf', '-O', 'test-output/round-table.gv'], make sure the Graphviz executables are on your systems' path

Now I am sure I have properly installed the correct dependencies. I first tried to set the correct environment variables. The graphviz executables are located at C:\Program Files (x86)\Graphviz2.37\binso I went to the Environment Variables section. There are two sections there: User Variables and System Variables. Under System Variables I clicked on Pathand then clicked Editand added ;C:\Program Files (x86)\Graphviz2.37\binto the end of the string and saved. This didn't clear the error.

现在我确定我已经正确安装了正确的依赖项。我首先尝试设置正确的环境变量。graphviz 可执行文件位于C:\Program Files (x86)\Graphviz2.37\bin所以我去了环境变量部分。有两个部分:用户变量和系统变量。在系统变量下,我单击路径,然后单击Edit并将;C:\Program Files (x86)\Graphviz2.37\bin 添加到字符串的末尾并保存。这并没有清除错误。

Then, following the answer given hereI uninstalled pydot (actually I use pydotplus here) and re-installed it again, but still no success.

然后,按照这里给出的答案我卸载了 pydot(实际上我在这里使用了 pydotplus)并重新安装了它,但仍然没有成功。

I have been trying for hours to fix this and the whole PATH variable thing is just confusing and frustrating.

我已经尝试了几个小时来解决这个问题,整个 PATH 变量的事情只是令人困惑和令人沮丧。

采纳答案by Morteza R

As it appears, Graphviz2.37 is known to have problems with the PATH variable on windows. I uninstalled it, removed the environment variables associated with it and instead downloaded and installed the newer beta version 2.39 and it now works like a charm.

众所周知,Graphviz2.37 在 Windows 上的 PATH 变量存在问题。我卸载了它,删除了与之关联的环境变量,而是下载并安装了较新的 beta 版本 2.39,现在它就像一个魅力。

回答by Plory.Truck

On jupyter(ipython) notebook with anaconda in win10 I solved the problem by conda install graphvizafter I had installed graphviz by pip install graphviz

在 jupyter(ipython) 笔记本上,在 win10 中conda install graphviz安装了 anaconda,我通过以下方式安装了graphviz 后解决了这个问题pip install graphviz

回答by nono

I had the same issue on Ubuntu(14.04) with Jupyter.

我在使用 Jupyter 的 Ubuntu(14.04) 上遇到了同样的问题。

To solve it I've added the dot library to python sys.path

为了解决它,我将点库添加到 python sys.path

First: check if dot is installed,

首先:检查点是否安装,

Then: find his path whereis dot-> /local/notebook/miniconda2/envs/ik2/bin/dot

然后:找到他的路径whereis dot-> /local/notebook/miniconda2/envs/ik2/bin/dot

Finally in python script : sys.path.append("/local/notebook/miniconda2/envs/ik2/bin/dot")

最后在 python 脚本中: sys.path.append("/local/notebook/miniconda2/envs/ik2/bin/dot")

回答by Silvia Bakalova

In my case (Win10, Anaconda3, Jupyter notebook) after "conda install graphviz"I have to add to the PATH: C:\Users\username\Anaconda3\Library\bin\graphviz

就我而言(Win10、Anaconda3、Jupyter 笔记本),"conda install graphviz"我必须添加到 PATH 之后:C:\Users\username\Anaconda3\Library\bin\graphviz

To modify PATH goto Control Panel > System and Security > System > Advanced System Settings > Environment Variables > Path > Edit > New

修改PATH转到 Control Panel > System and Security > System > Advanced System Settings > Environment Variables > Path > Edit > New

回答by Aris

I solved it installing directly from https://graphviz.gitlab.io/_pages/Download/Download_windows.htmland including in windows path:

我解决了它直接从https://graphviz.gitlab.io/_pages/Download/Download_windows.htmlWindows 路径安装并包含在 Windows 路径中的问题:

C:\Program Files (x86)\Graphviz2.38\bin

C:\Program Files (x86)\Graphviz2.38

After I restart windows

在我重新启动 Windows 之后

回答by HymanChen

when you add C:\Program Files (x86)\Graphviz2.38\bin to PATH, then you must close your IDE enviroment such as spyder and restart, you'll solve the "RuntimeError:make sure the Graphviz executables are on your systems' path"

当您将 C:\Program Files (x86)\Graphviz2.38\bin 添加到 PATH 时,您必须关闭 spyder 等 IDE 环境并重新启动,您将解决“运行时错误:确保 Graphviz 可执行文件在您的系统上” ' 小路”

回答by HymanCHEN

To solve this problem,when you install graphviz2.38 successfully, then add your PATH variable to system path.Under System Variables you can click on Path and then clicked Edit and added ;C:\Program Files (x86)\Graphviz2.38\bin to the end of the string and saved.After that,restart your pythonIDE like spyper,then it works well.

为了解决这个问题,当你成功安装graphviz2.38时,然后将你的PATH变量添加到系统路径中。在系统变量下,你可以点击路径,然后点击编辑并添加;C:\Program Files (x86)\Graphviz2.38\ bin 到字符串的末尾并保存。之后,像 spyper 一样重新启动你的 pythonIDE,然后它运行良好。

Don't forget to close Spyder and then restart.

不要忘记关闭Spyder,然后重新启动。

回答by tom4everitt

I also had this problem on Ubuntu 16.04.

我在 Ubuntu 16.04 上也遇到了这个问题。

Fixed by running sudo apt-get install graphvizin addition to the pip install I had already performed.

sudo apt-get install graphviz除了我已经执行的 pip install 之外,还通过运行来修复。

回答by njgiv

I had the same issue with Windows 10.

我在 Windows 10 上遇到了同样的问题。

First, I installed graphviz-2.38.0with the following command without any problem...

首先,我graphviz-2.38.0使用以下命令安装没有任何问题......

install -c anaconda graphviz=2.38.0

Second, I installed pydotpluswith the following command without any problem...

其次,我pydotplus使用以下命令安装没有任何问题......

install -c conda-forge pydotplus

After that, when I got to my step to visualize my decision tree had the following issue with {InvocationException: GraphViz's executables not found}...

在那之后,当我开始可视化我的决策树时,遇到了以下问题{InvocationException: GraphViz's executables not found}......

C:\Users\admin\Anaconda3\lib\site-packages\pydotplus\graphviz.py in create(self, prog, format)
   1958             if self.progs is None:
   1959                 raise InvocationException(
-> 1960                     'GraphViz\'s executables not found')
   1961 
   1962         if prog not in self.progs:

InvocationException: GraphViz's executables not found

In my case, all I had to do to fix it is to put the environment path of the graphvizexecutables in my user PATHenvironment variable and this fixed it. Just make sure it is the path where YOUR.exefiles are located :)

就我而言,我所要做的就是将graphviz可执行文件的环境路径放在我的用户PATH环境变量中,然后修复它。只要确保它是YOUR.exe文件所在的路径:)

C:\Users\admin\Anaconda3\pkgs\graphviz-2.38.0-4\Library\bin\graphviz

回答by Veggiet

Because Mac OS has not been mentioned I will add that I had the same problem on OS X Yosemite, the solution I found was to do brew install graphviz

因为没有提到 Mac OS,我会补充说我在 OS X Yosemite 上遇到了同样的问题,我找到的解决方案是 brew install graphviz

This solved the problem, not sure if I shouldn't have just edited one of the other answers in this list, because they all seem to be the same answer, just install an official package in addition to the Python Library.

这解决了问题,不确定我是否应该编辑此列表中的其他答案之一,因为它们似乎都是相同的答案,只需安装除 Python 库之外的官方软件包即可。