2017-02-23 71 views
0

我必須在Jupyter筆記本上運行以下代碼。Python 3.4 graphviz問題

from graphviz import Digraph 
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) 

我必須事先安裝graphviz。在Windows 10上安裝graphviz 2.38後,我做了'pip install graphviz' 和'conda install graphviz'。但我得到這個錯誤

「RuntimeError:未能執行[‘點’,‘-Tsvg’],確保Graphviz的可執行文件是您的系統路徑」

我應該做的還有什麼,使這個錯誤消失了?

回答

0

您的python運行時正在運行PATH環境變量,該變量不包含graphviz的路徑。

您可以通過檢查以下(PY 3)碼,以確認這一點:

import os 
print(os.environ['PATH']) 

確實列出在已安裝graphviz的目錄。如果還沒有,修改你的系統PATH環境變量[1],或每次添加的路徑,graphviz的二進制文件用下面的命令前執行的Python:

set PATH=%PATH%;this_would_be_the_path_to_your_graphiz_binaries_like_dot 

[1] https://superuser.com/questions/284342/what-are-path-and-other-environment-variables-and-how-can-i-set-or-use-them