【问题标题】:Python graphviz - pydot.Dot.write_png doesn't work on WindowsPython graphviz - pydot.Dot.write_png 在 Windows 上不起作用
【发布时间】:2013-05-02 07:40:24
【问题描述】:

我正在使用 Python 通过pydot.Dot 创建图表。

当我想将图形写入 PNG 时,我使用 pydot.Dot.write_png(...)。 不幸的是,它在找到 graphviz 的阶段失败了(在一个名为 find_graphviz 的函数中)。

我尝试将其作为软件安装,但不知道如何将其导入 Python。

我该如何解决这个问题?

【问题讨论】:

    标签: python pydot


    【解决方案1】:

    尝试手动将 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.
    """
    

    【讨论】:

    • 谢谢。我这样做了,但是在注册表阶段仍然出现错误,即似乎是在注册表中没有找到它时发生的错误,但没有继续进行路径搜索:#错误:(2, 'RegOpenKeyEx', '系统找不到指定的文件') #
    • 好的 - 我刚刚在 pydot.py 的第 432 行添加了“and False”,这样它就会跳过注册表部分并转到路径方法。
    【解决方案2】:

    即使将 Graphviz 添加到我的 PATH 后,它也无法正常工作。我最终进入 pydot.py 文件并注释掉 find_graphviz() 中的所有内容并在行中写入:

    `return {'dot': 'C:\\Program Files\\graphviz-2.38\\bin\\dot.exe'}`
    

    这是我的 dot 文件所在的位置,您可能将它放在不同的位置。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-03
      • 2020-02-16
      • 2015-04-21
      • 2020-07-08
      • 2014-05-08
      • 1970-01-01
      • 2020-07-20
      • 1970-01-01
      相关资源
      最近更新 更多