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

Graphviz';找不到的可执行文件(Python 3.4),python,path,graphviz,pydot,Python,Path,Graphviz,Pydot,我正在Windows7上运行Python3.4。我正在尝试为graphviz使用Python接口。这是我打算运行的脚本: 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

我正在Windows7上运行Python3.4。我正在尝试为graphviz使用Python接口。这是我打算运行的脚本:

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)
我在运行时遇到以下错误:

RuntimeError: failed to execute ['dot', '-Tpdf', '-O', 'test-output/round-table.gv'], make sure the Graphviz executables are on your systems' path
现在我确信我已经正确安装了正确的依赖项。我首先尝试设置正确的环境变量。graphviz可执行文件位于C:\Program Files(x86)\graphviz 2.37\bin中,因此我转到了环境变量部分。这里有两个部分:用户变量和系统变量。在“系统变量”下,我单击了路径,然后单击编辑,添加了内容;将C:\Program Files(x86)\Graphviz2.37\bin添加到字符串末尾并保存。这并没有清除错误

然后,根据答案,我卸载了pydot(实际上我在这里使用pydotplus)并重新安装,但仍然没有成功


我已经尝试了几个小时来解决这个问题,而整个路径变量的问题令人困惑和沮丧。

正如它所显示的,Graphviz2.37在windows上的路径变量存在问题。我卸载了它,删除了与之相关的环境变量,而是下载并安装了更新的beta版本2.39,现在它就像一个魔咒一样工作。

在jupyter(ipython)上win10中带有anaconda的笔记本电脑我通过
conda安装graphviz
解决了这个问题。在我通过
pip安装graphviz

安装graphviz之后,我在Ubuntu(14.04)和Jupyter上遇到了同样的问题

为了解决这个问题,我在pythonsys.path中添加了点库

第一:检查是否安装了dot

然后: 找到他的路径
点在哪里
->/local/notebook/miniconda2/envs/ik2/bin/dot

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

在我的例子中(Win10、Anaconda3、Jupyter notebook),在
之后,“conda安装graphviz”
我必须添加到路径:
C:\Users\username\Anaconda3\Library\bin\graphviz


要修改路径,请转到
控制面板>系统和安全>系统>高级系统设置>环境变量>路径>编辑>新建
我解决了直接从
安装的问题https://graphviz.gitlab.io/_pages/Download/Download_windows.html
并包括在windows路径中:

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

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

在我重新启动windows之后,当您将C:\Program Files(x86)\Graphviz 2.38\bin添加到PATH中时,您必须关闭IDE环境(如spyder)并重新启动,您将解决“运行时错误:确保Graphviz可执行文件位于系统路径上”

要解决此问题,请在成功安装Graphviz 2.38后,然后将您的路径变量添加到系统路径。在系统变量下,您可以单击路径,然后单击编辑并添加;将C:\Program Files(x86)\Graphviz2.38\bin添加到字符串末尾并保存。然后,像spyper一样重新启动pythonIDE,它就会正常工作


别忘了关闭Spyder,然后重新启动。

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


除了我已经执行的pip安装之外,通过运行sudo apt get install graphviz
进行修复。

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

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

install -c anaconda graphviz=2.38.0
install -c conda-forge pydotplus
其次,我使用以下命令安装了
pydotplus
,没有任何问题

install -c anaconda graphviz=2.38.0
install -c conda-forge pydotplus
在那之后,当我开始可视化我的决策树时,
{InvocationException:GraphViz的可执行文件找不到}

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
在我的例子中,我所要做的就是将
graphviz
可执行文件的环境路径放在我的user
path
环境变量中,这就解决了它。只需确保它是
您的.exe文件所在的路径:)


由于没有提到Mac OS,我要补充的是,我在OS X Yosemite上也遇到了同样的问题,我找到的解决方案是执行
brew安装graphviz

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

只需安装即可

conda install graphviz
然后安装

conda install -c conda-forge pydotplus

对于Windows8.1和Python2.7,我通过以下步骤修复了这个问题

一,。下载并安装graphviz-2.38.msi

二,。设置路径变量

  • 控制面板>系统和安全>系统>高级系统设置>环境变量>路径>编辑
  • 添加“C:\ProgramFiles(x86)\Graphviz2.38\bin”

我在Anaconda 3上使用Windows 10和Python 3.6,并且遇到了同样的问题

我通过按顺序执行以下操作使其正常工作:

  • 从Anaconda终端:pip安装pydotplus
  • 从Anaconda终端:conda安装pydotplus
  • 从Anaconda码头:pip安装graphviz
  • 来自Anaconda终端:conda安装graphviz
  • 转到Windows环境变量、路径,并在Anaconda的graphviz目录下添加了my dot.exe文件的位置

  • 之后工作正常。

    如果您在Win10上,请安装Graphviz,然后使用以下命令添加路径

    import os
    os.environ["PATH"] += os.pathsep + 'C:\Program Files (x86)\Graphviz2.38/bin/'
    

    请注意,我使用的是windows 10。以下部分可能适用于或不适用于其他版本的windows或操作系统:

    **注2:*
    “系统上的Graphviz bin文件地址”可以是C:\Program Files(x86)\Graphviz 2.38\bin或安装Graphviz的任何其他路径。

    我们不仅在Graphviz上有问题,而且在Jupyter中要使用的其他外部EXE文件上也有问题。
    原因是当jupyter想要导入一个包时,它会在工作目录中查找该包,当它找不到该包时,它会返回此类错误。
    我们能做的就是解决这个问题如下:
    1) 检查您的系统上是否安装了Graphviz,如果没有,您可以
    import os
    os.environ["PATH"] += os.pathsep + r'the Graphviz bin file address on your system'
    
    def create(self, prog=None, format='ps'):
    
    if prog not in self.progs:
        raise InvocationException(
            'GraphViz\'s executable "%s" not found' % prog)
    
    if not os.path.exists(self.progs[prog]) or \
            not os.path.isfile(self.progs[prog]):
        raise InvocationException(
            'GraphViz\'s executable "{}" is not'
            ' a file or doesn\'t exist'.format(self.progs[prog])
        )
    
      self.progs[prog] = "C:/Program Files (x86)/Graphviz2.38/bin/gvedit.exe"`
    
    if prog not in self.progs:
        raise InvocationException(
            'GraphViz\'s executable "%s" not found' % prog)
    
    self.progs[prog] = "C:/Program Files (x86)/Graphviz2.38/bin/gvedit.exe"
    
    if not os.path.exists(self.progs[prog]) or \
            not os.path.isfile(self.progs[prog]):
        raise InvocationException(
            'GraphViz\'s executable "{}" is not'
            ' a file or doesn\'t exist'.format(self.progs[prog])
        )
    
    conda install -c anaconda graphviz
    conda install -c conda-forge python-graphviz
    
    import sklearn.datasets as datasets
    import pandas as pd
    from sklearn.tree import DecisionTreeClassifier
    iris=datasets.load_iris()
    df=pd.DataFrame(iris.data, columns=iris.feature_names)
    y=iris.target
    
    dtree=DecisionTreeClassifier()
    dtree.fit(df,y)
    
    from sklearn.externals.six import StringIO  
    from IPython.display import Image  
    from sklearn.tree import export_graphviz
    import pydotplus
    import graphviz
    import os
    os.environ\["PATH"\] += os.pathsep + 'C:/Users/tstusr/AppData/Local/Continuum/anaconda3/pkgs/Graphviz2.38/bin'
    
    dot_data = StringIO()
    export_graphviz(dtree, out_file=dot_data,  
                    filled=True, rounded=True,
                    special_characters=True)
    graph = pydotplus.graph_from_dot_data(dot_data.getvalue())  
    Image(graph.create_png())
    
    import os
    
    os.environ['PATH'] = os.environ['PATH']+';'+os.environ['CONDA_PREFIX']+r"\Library\bin\graphviz"
    
    import sys
    
    sys.path.append('C:/Users/usrname/AppData/Local/Continuum/anaconda3/Library/bin/graphviz/')
    
    dot.set_graphviz_executables( {'dot': r'C:\Program Files\Graphviz\bin\dot.exe'})
    
        This method allows to manually specify the location of the GraphViz
        executables.
    
        The argument to this method should be a dictionary where the keys are
        as follows:
    
            {'dot': '', 'twopi': '', 'neato': '', 'circo': '', 'fdp': ''}
    
        and the values are the paths to the corresponding executable,
        including the name of the executable itself.