OSError: `pydot` failed to call GraphViz.Please install GraphViz (https://www.graphviz.org/) and ensure that its executables are in the $PATH.
爲了保持教程的完整性,從頭開始說:
1,安裝Graphviz軟件
https://graphviz.gitlab.io/_pages/Download/Download_windows.html
下載smi文件一路next安裝即可
2,配置Graphviz軟件環境變量
添加安裝目錄下的 bin 文件到 系統變量 Path 下,我安裝在了 D:\Graphviz2.38\,因此
Path=D:\Graphviz2.38\bin;
3. GraphViz 找不到的問題,是因爲在 win + conda 環境下默認後綴爲 .bat,看代碼:
import pydot_ng as pydot
print(pydot.find_graphviz())
import pydot
print('檢測到的系統變量爲:%s' % (os.environ.get('PATH', '')))
print('當前系統是否爲 window: %s' % (pydot.is_windows()))
print('當前環境是否使用了conda: %s' % (pydot.is_anacoda()))
print('執行文件的後綴爲:%s' % (pydot.get_executable_extension()))
可以看到,並沒有 dot.bat 在上述路徑中,怎麼辦呢?
還記得剛纔添加的 Path 吧,那我就在 D:\Graphviz2.38\bin 路徑下複製出來一個
把 dot.exe ==> 複製一份重命名爲 dot.bat,確實是找到了(PS:我的依然報錯,這顯然不是很好的解決辦法)。
既然這樣,我就刪除了剛纔複製出來的 dot.bat,尋找其他的辦法。
我在 (https://github.com/pydot/pydot/issues/205)中看到,
解決找不到的方法:
conda install -c anaconda graphviz
原因:
pydot通過conda安裝,它只支持conda安裝的graphviz。
可以看到,在虛擬環境 的 \Library\bin 中已經可以看到 dot.bat 了
網上也有的說:
改源碼,我不是太喜歡這種方式。大家可以自主選擇