Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在Spyder 3.6中安装GraphViz_Python_Spyder - Fatal编程技术网

Python 如何在Spyder 3.6中安装GraphViz

Python 如何在Spyder 3.6中安装GraphViz,python,spyder,Python,Spyder,我看到了一个堆栈溢出存储库,其中提到了先“pip安装GraphViz”,然后“pip安装pydotplus”。现在我已经在我的C:\Users\ChirantanGupta\Downloads\WinPython-64bit-3.6.0.0\python-3.6.0b3.amd64\Lib\site软件包中成功安装了这两个程序。两者都存在,但每当我尝试运行此代码时,都会显示一个错误: 错误是: 文件“C:\Users\ChirantanGupta\Downloads\WinPython-64bi

我看到了一个堆栈溢出存储库,其中提到了先“pip安装GraphViz”,然后“pip安装pydotplus”。现在我已经在我的C:\Users\ChirantanGupta\Downloads\WinPython-64bit-3.6.0.0\python-3.6.0b3.amd64\Lib\site软件包中成功安装了这两个程序。两者都存在,但每当我尝试运行此代码时,都会显示一个错误: 错误是:

文件“C:\Users\ChirantanGupta\Downloads\WinPython-64bit-3.6.0.0\python-3.6.0b3.amd64\lib\site packages\pydotplus\graphviz.py”,第1918行,以书面形式 fobj.write(自创建(程序,格式))

文件“C:\Users\ChirantanGupta\Downloads\WinPython-64bit-3.6.0.0\python-3.6.0b3.amd64\lib\site packages\pydotplus\graphviz.py”,第1960行,在create中 '未找到GraphViz的可执行文件')

调用异常:找不到GraphViz的可执行文件

代码如下:

from sklearn.datasets import load_iris
from sklearn import tree
iris = load_iris()
clf = tree.DecisionTreeClassifier()
clf = clf.fit(iris.data, iris.target)
with open("iris.dot", 'w') as f:
    f = tree.export_graphviz(clf, out_file=f)
import os
os.unlink('iris.dot')

import pydotplus 
dot_data = tree.export_graphviz(clf, out_file=None) 
graph = pydotplus.graph_from_dot_data(dot_data) 
graph.write_pdf("iris.pdf") 

from IPython.display import Image  
dot_data = tree.export_graphviz(clf, out_file=None,feature_names=iris.feature_names,  
                         class_names=iris.target_names,  
                         filled=True, rounded=True,  
                         special_characters=True)
graph = pydotplus.graph_from_dot_data(dot_data)  
Image(graph.create_png())
也许可以试试这个:

  • 找到“\WinPython-64bit-3.6.0”旁边的“python.\u pth”文件‌​.0\python-3.6.0b3.am‌​d64\python.exe“
  • 将其重命名为“zpython.\u pth”

要在WinPython中安装Graphviz:

  • 确保已安装Graphviz可执行文件。如果没有,请转到,下载Windows二进制文件并将其安装到所需位置。例如,假设安装后Graphviz根目录为
    c:\tools\Graphviz
  • 确保将Graphviz
    bin
    子文件夹添加到您的
    PATH
    环境变量中。按照以下示例,打开命令提示窗口并键入:

    setx PATH=%PATH%;c:\tools\graphviz\bin;
    
  • 使用
    pip
    或使用WinPython软件包管理器在WinPython中安装
    graphviz
    软件包(有关更多详细信息,请参阅)

  • 通过运行Graphviz示例,测试所有功能是否正常工作

  • 您还需要安装graphviz本身。您已经安装了一个python库,可以从python调用GraphViz,但不能从实际的GraphViz可执行文件中调用。我已经将GraphViz安装为GraphViz-2.38.zip,并在路径C:\Users\ChirantanGupta\Downloads\WinPython-64bit-3.6.0.0\python-3.6.0b3.amd64\Lib\site packages上解压缩它。但是我的代码给出了和以前一样的错误。我在过去的两天里一直在尝试这个简单的事情。请帮忙。你安装了pygraphviz吗?我知道你是用pip install Graphviz安装Graphviz的,但是你有没有用pip install pygraphviz?没有,我没有,因为在任何地方都没有提到这一点。不确定它是否会起作用,但值得一试。这对我来说很有效。要将Graphviz添加到
    路径
    中,我使用了:
    setx路径“%PATH%;C:\tools\Graphviz\bin”