【发布时间】:2018-08-04 14:55:02
【问题描述】:
我已经下载了 graphviz 文件并将它们放在我的 PC 的目录 C:\graphviz 中(我运行的是 Windows 10)。
然后我将可执行文件的地址添加到系统的 PATH 中:
当我运行诊断代码时:
from graphviz import Digraph
dot = Digraph(comment='The Round Table')
dot #doctest: +ELLIPSIS
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) # doctest: +NORMALIZE_WHITESPACE
dot.render('test-output/round-table.gv', view=True) # doctest: +SKIP
我得到一个例外:
// The Round Table
digraph {
A [label="King Arthur"]
B [label="Sir Bedevere the Wise"]
L [label="Sir Lancelot the Brave"]
A -> B
A -> L
B -> L [constraint=false]
}
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
C:\ProgramData\Anaconda3\lib\site-packages\graphviz\backend.py in render(engine, format, filepath, quiet)
128 try:
--> 129 subprocess.check_call(args, stderr=stderr, **POPEN_KWARGS)
130 except OSError as e:
C:\ProgramData\Anaconda3\lib\subprocess.py in check_call(*popenargs, **kwargs)
285 """
--> 286 retcode = call(*popenargs, **kwargs)
287 if retcode:
C:\ProgramData\Anaconda3\lib\subprocess.py in call(timeout, *popenargs, **kwargs)
266 """
--> 267 with Popen(*popenargs, **kwargs) as p:
268 try:
C:\ProgramData\Anaconda3\lib\subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, encoding, errors)
706 errread, errwrite,
--> 707 restore_signals, start_new_session)
708 except:
C:\ProgramData\Anaconda3\lib\subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, unused_restore_signals, unused_start_new_session)
991 os.fspath(cwd) if cwd is not None else None,
--> 992 startupinfo)
993 finally:
FileNotFoundError: [WinError 2] The system cannot find the file specified
During handling of the above exception, another exception occurred:
ExecutableNotFound Traceback (most recent call last)
<ipython-input-1-1b23fb1e1f3e> in <module>()
14 print(dot.source) # doctest: +NORMALIZE_WHITESPACE
15
---> 16 dot.render('test-output/round-table.gv', view=True) # doctest: +SKIP
C:\ProgramData\Anaconda3\lib\site-packages\graphviz\files.py in render(self, filename, directory, view, cleanup)
174 filepath = self.save(filename, directory)
175
--> 176 rendered = backend.render(self._engine, self._format, filepath)
177
178 if cleanup:
C:\ProgramData\Anaconda3\lib\site-packages\graphviz\backend.py in render(engine, format, filepath, quiet)
130 except OSError as e:
131 if e.errno == errno.ENOENT:
--> 132 raise ExecutableNotFound(args)
133 else: # pragma: no cover
134 raise
ExecutableNotFound: failed to execute ['dot', '-Tpdf', '-O', 'test-output/round-table.gv'], make sure the Graphviz executables are on your systems' PATH
以下内容也可能有助于诊断:
【问题讨论】:
-
我没有看到任何证据表明
C:\graphviz\bin目录是您的系统路径(即您提供的图片中的变量 Path)的 9n。尝试在终端窗口中运行:where dot.exe和dot --help看看会发生什么。 -
@albert 谢谢。我按照你的建议做了。请参阅我的帖子以及这些操作的结果。我不确定这些消息意味着什么,也不知道如何解决问题。
-
奇怪,有点矛盾,一方面它找到了点(dot -V),另一方面却没有(dot.exe)。你可以试试
where dot吗? -
您创建了一个名为
graphviz的新环境变量,并为其分配了一个值。您没有将相应的目录附加到您的PATH变量中。您似乎还试图逃避路径分隔符。这不是必需的。
标签: windows python-3.x path graphviz