我下载了Graphviz 2.38
MSI版本并安装在文件夹C:\Python34
下,然后运行pip安装Graphviz
,一切都很顺利。在系统的路径中,我添加了C:\Python34\bin
。当我试图运行测试脚本时,在filename=dot行。render(filename='test')
,我收到一条消息
RuntimeError: failed to execute ['dot', '-Tpdf', '-O', 'test'], make sure the Graphviz executables are on your systems' path
我试图将“C:\Python34\bin\dot.exe”
放在系统的路径中,但它不起作用,我甚至创建了一个新的环境变量“GRAPHVIZ\u dot”
,其值为“C:\Python34\bin\dot.exe”
,但仍然不起作用。我尝试卸载Graphviz和pip卸载Graphviz
,然后重新安装它并再次安装pip,但没有任何效果。
整个回溯消息是:
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\graphviz\files.py", line 220, in render
proc = subprocess.Popen(cmd, startupinfo=STARTUPINFO)
File "C:\Python34\lib\subprocess.py", line 859, in __init__
restore_signals, start_new_session)
File "C:\Python34\lib\subprocess.py", line 1112, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Documents\Kissmetrics\curves and lines\eventNodes.py", line 56, in <module>
filename=dot.render(filename='test')
File "C:\Python34\lib\site-packages\graphviz\files.py", line 225, in render
'are on your systems\' path' % cmd)
RuntimeError: failed to execute ['dot', '-Tpdf', '-O', 'test'], make sure the Graphviz executables are on your systems' path
有人有这方面的经验吗?
您应该在系统中安装graphviz包(不仅仅是python包)。在Ubuntu上,您应该尝试:
sudo apt-get install graphviz
import os
os.environ["PATH"] += os.pathsep + 'D:/Program Files (x86)/Graphviz2.38/bin/'
在windows中,只需在开头添加这两行,其中'D:/Program Files(x86)/Graphviz2。38/bin/”替换为您的bin文件所在的地址。
这就解决了问题。
这一个解决了我在MAC上的问题:
brew install graphviz