背景:
在使用jupyter阅读fastbook时一些用代码生成的图不能正常显示,在执行相应代码时报错如下:
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
~/.local/lib/python3.6/site-packages/graphviz/backend.py in run(cmd, input, capture_output, check, encoding, quiet, **kwargs)
163 try:
--> 164 proc = subprocess.Popen(cmd, startupinfo=get_startupinfo(), **kwargs)
165 except OSError as e:
/usr/lib/python3.6/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)
728 errread, errwrite,
--> 729 restore_signals, start_new_session)
730 except:
/usr/lib/python3.6/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, restore_signals, start_new_session)
1363 err_msg += ': ' + repr(err_filename)
-> 1364 raise child_exception_type(errno_num, err_msg, err_filename)
1365 raise child_exception_type(err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'dot': 'dot'
During handling of the above exception, another exception occurred:
ExecutableNotFound Traceback (most recent call last)
~/.local/lib/python3.6/site-packages/IPython/core/formatters.py in __call__(self, obj)
343 method = get_real_method(obj, self.print_method)
344 if method is not None:
--> 345 return method()
346 return None
347 else:
~/.local/lib/python3.6/site-packages/graphviz/files.py in _repr_svg_(self)
142
143 def _repr_svg_(self):
--> 144 return self.pipe(format='svg').decode(self._encoding)
145
146 def pipe(self, format=None, renderer=None, formatter=None, quiet=False):
~/.local/lib/python3.6/site-packages/graphviz/files.py in pipe(self, format, renderer, formatter, quiet)
169 out = backend.pipe(self._engine, format, data,
170 renderer=renderer, formatter=formatter,
--> 171 quiet=quiet)
172
173 return out
~/.local/lib/python3.6/site-packages/graphviz/backend.py in pipe(engine, format, data, renderer, formatter, quiet)
246 """
247 cmd, _ = command(engine, format, None, renderer, formatter)
--> 248 out, _ = run(cmd, input=data, capture_output=True, check=True, quiet=quiet)
249 return out
250
~/.local/lib/python3.6/site-packages/graphviz/backend.py in run(cmd, input, capture_output, check, encoding, quiet, **kwargs)
165 except OSError as e:
166 if e.errno == errno.ENOENT:
--> 167 raise ExecutableNotFound(cmd)
168 else:
169 raise
ExecutableNotFound: failed to execute ['dot', '-Kdot', '-Tsvg'], make sure the Graphviz executables are on your systems' PATH
解决方法:
安装graphviz,如在ubuntu上可以通过命令行执行:
sudo apt-get install graphviz
解决过程:
从错误提示信息看到:
ExecutableNotFound: failed to execute ['dot', '-Kdot', '-Tsvg'], make sure the Graphviz executables are on your systems' PATH
可以判断是在调用程序Graphviz时找不到这个程序的可执行文件,有可能没有安装。查找ubuntu安装Graphviz方法,并尝试安装后问题解决.