2013-05-08 31 views
2

我正在使用Python通過pydot.Dot創建圖形。 當我想將圖形寫入PNG時,我使用pydot.Dot.write_png(...)。 不幸的是,它在尋找graphviz的階段失敗了(在一個名爲find_graphviz的函數中)。Python graphviz - pydot.Dot.write_png does not work(windows)

我試着將它安裝爲一個軟件,但我看不到它是如何導入到Python的。

任何人都遇到過這個問題?

謝謝。

回答

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. 
""" 
+0

謝謝。我這樣做了,但是我仍然在註冊階段出現錯誤,即它看起來像是在註冊表中沒有找到它時發生的錯誤,但是沒有繼續搜索路徑: #error:(2 ,'RegOpenKeyEx','系統找不到指定的文件')# – yoki 2013-05-08 20:36:10

+0

好的 - 我在pydot.py的第432行添加了「False」,這樣它就會跳過註冊表部分並轉到路徑方法。 – yoki 2013-05-09 05:31:47

4

即使在將Graphviz添加到我的PATH後,它仍然無法工作。我最終進入了pydot.py文件,並註釋掉find_graphviz一切(),並在該行寫:

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

這就是我點文件的位置,你可能有它在不同的位置。