【发布时间】:2013-05-02 07:40:24
【问题描述】:
我正在使用 Python 通过pydot.Dot 创建图表。
当我想将图形写入 PNG 时,我使用 pydot.Dot.write_png(...)。
不幸的是,它在找到 graphviz 的阶段失败了(在一个名为 find_graphviz 的函数中)。
我尝试将其作为软件安装,但不知道如何将其导入 Python。
我该如何解决这个问题?
【问题讨论】:
我正在使用 Python 通过pydot.Dot 创建图表。
当我想将图形写入 PNG 时,我使用 pydot.Dot.write_png(...)。
不幸的是,它在找到 graphviz 的阶段失败了(在一个名为 find_graphviz 的函数中)。
我尝试将其作为软件安装,但不知道如何将其导入 Python。
我该如何解决这个问题?
【问题讨论】:
尝试手动将 Graphviz\bin 文件夹添加到系统 PATH。
>>> import pydot
>>> pydot.find_graphviz()
{'dot': 'C:\\Program Files (x86)\\Graphviz 2.28\\bin\\dot.exe'} #...
>>> print pydot.find_graphviz.__doc__
"""
Locate Graphviz's executables in the system.
Tries three methods:
First: Windows Registry (Windows only)
This requires Mark Hammond's pywin32 is installed.
Secondly: Search the path
It will look for 'dot', 'twopi' and 'neato' in all the directories
specified in the PATH environment variable.
Thirdly: Default install location (Windows only)
It will look for 'dot', 'twopi' and 'neato' in the default install
location under the "Program Files" directory.
It will return a dictionary containing the program names as keys
and their paths as values.
If this fails, it returns None.
"""
【讨论】:
即使将 Graphviz 添加到我的 PATH 后,它也无法正常工作。我最终进入 pydot.py 文件并注释掉 find_graphviz() 中的所有内容并在行中写入:
`return {'dot': 'C:\\Program Files\\graphviz-2.38\\bin\\dot.exe'}`
这是我的 dot 文件所在的位置,您可能将它放在不同的位置。
【讨论】: