Graphviz如何与Anaconda/Spyder一起使用? [英] How to use Graphviz with Anaconda/Spyder?
问题描述
我正在尝试从Spyder使用Graphviz(通过Anaconda安装).我无法理解执行此操作所需的内容以及如何加载程序包,设置变量等.
I am attempting to use Graphviz from Spyder (via an Anaconda install). I am having trouble understanding what is needed to do this and how to go about loading packages, setting variables, etc.
对于一个新的Python以及Graphviz和Spyder用户,我直截了当的方法会很棒!
I straight forward approach for a new Python and Graphviz and Spyder user would be great!
此外,除了仅创建和运行Graphviz之外,如何使用预先生成的.gv文件从python运行Graphviz?
Also, apart from just creating and running Graphviz, how can one run Graphviz from python with a pre-generated .gv file?
推荐答案
以下是对我有用的步骤.这些信息大部分可用,但分布在几个不同的StackOverflow帖子和其他网站中.我希望这是一个很好的一站式资源.
Here are the steps that worked for me. Much of this information was available but spread out in several different StackOverflow posts and other websites. I hope that this serves as a good one-stop resource.
-
转到 Graphviz网站,然后下载并安装到您的计算机上(无需安装适用于所有用户).
Go to the Graphviz website and download and install to your computer (do NOT need to install for all users).
从 Continuum网站下载并安装Anaconda3.5.
Download and install Anaconda3.5 from the Continuum website.
将Graphviz添加到环境变量"Path":
Add Graphviz to the environment variable "Path":
- 转到
计算机>属性>高级系统设置>环境变量
,然后在系统变量框中找到路径".单击路径,然后单击编辑. - 将
; C:\ Program Files(x86)\ Graphviz2.38 \ bin
附加到Path中已经存在的许多路径的末尾.请注意,Graphviz的路径可能与您不同,因此请确保输入正确的路径.文件夹"bin"应包含许多文件,包括dot.exe
应用程序. - 要检查安装,请转到命令提示符并输入:
dot -V
,这应该返回已安装的Graphviz的版本.例如,dot-graphviz版本2.38.0
.如果这不起作用,请输入set
并查找Graphviz路径.
- Go to
Computer > Properties > Advanced system settings > Environment Variables
and then find "Path" in the system variables box. Click on Path and click edit. - Append
;C:\Program Files (x86)\Graphviz2.38\bin
to the end of the many paths that are already present in Path. Note, the path to Graphviz may be different for you so make sure to put the correct path. The folder "bin" should have many files including thedot.exe
application. - To check the install go to the command prompt and enter:
dot -V
this should return the version of Graphviz installed. For example,dot - graphviz version 2.38.0
. If this does not work, enterset
and look for the Graphviz path.
转到Anaconda命令提示符并输入: pip install graphviz
Go to the Anaconda command prompt and enter: pip install graphviz
重新启动Spyder或启动它(如果尚未打开的话).
Restart Spyder or launch it if not already open.
现在在您的Python脚本中添加 import graphviz
Now within your Python script add import graphviz
下面是一个如何在Graphviz教程中使用Graphviz创建图形并呈现图形的示例
Below is an example of how to create a graph and render it using Graphviz from a Graphviz tutorial
import graphviz
dot = graphviz.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')
dot.render('FileName', view=True)
下面是如何从预先生成的.gv文件(至少是探索的起点)创建图形的示例
Below is an example of how to create a graph from a pre-generated .gv file (at least a starting point for exploration)
from graphviz import Source
Source.from_file('file.gv')
使用完整链接:
使用的版本:
Anaconda 3.5(Spyder附带)
Anaconda 3.5 (comes with Spyder)
Graphviz 2.38
Graphviz 2.38
这篇关于Graphviz如何与Anaconda/Spyder一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!