我在 Windows 7 上运行 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)\Graphviz2.37\bin所以我去了环境变量部分。那里有两个部分:用户变量和系统变量。在系统变量下我单击Path然后点击Edit
并添加了;C:\Program Files (x86)\Graphviz2.37\bin到字符串末尾并保存。这并没有清除错误。
然后,按照答案在这里给出我卸载了pydot(实际上我这里使用的是pydotplus)并重新安装了一遍,但仍然没有成功。
我已经尝试了几个小时来解决这个问题,整个 PATH 变量的事情只是令人困惑和令人沮丧。