1

I'm learning ML with Python based on a book "Introduction to Machine Learning with Python" by Andreas C. Müller & Sarah Guido. So, please forgive if I ask a very basic question. I followed one code below from the book,

mglearn.plots.plot_animal_tree()

in order to produce a figure as attached: enter image description here

I already installed graphviz using command line:

pip install graphviz

and attached the package in jupyter notebook:

import graphviz

However, the issue was still created as below that the figure can not be generated:

---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
File D:\Python\lib\site-packages\graphviz\backend\execute.py:81, in run_check(cmd, input_lines, encoding, quiet, **kwargs)
     80     else:
---> 81         proc = subprocess.run(cmd, **kwargs)
     82 except OSError as e:

File D:\Python\lib\subprocess.py:501, in run(input, capture_output, timeout, check, *popenargs, **kwargs)
    499     kwargs['stderr'] = PIPE
--> 501 with Popen(*popenargs, **kwargs) as process:
    502     try:

File D:\Python\lib\subprocess.py:969, in Popen.__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, user, group, extra_groups, encoding, errors, text, umask, pipesize)
    966             self.stderr = io.TextIOWrapper(self.stderr,
    967                     encoding=encoding, errors=errors)
--> 969     self._execute_child(args, executable, preexec_fn, close_fds,
    970                         pass_fds, cwd, env,
    971                         startupinfo, creationflags, shell,
    972                         p2cread, p2cwrite,
    973                         c2pread, c2pwrite,
    974                         errread, errwrite,
    975                         restore_signals,
    976                         gid, gids, uid, umask,
    977                         start_new_session)
    978 except:
    979     # Cleanup if the child failed starting.

File D:\Python\lib\subprocess.py:1438, in Popen._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_gid, unused_gids, unused_uid, unused_umask, unused_start_new_session)
   1437 try:
-> 1438     hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
   1439                              # no special security
   1440                              None, None,
   1441                              int(not close_fds),
   1442                              creationflags,
   1443                              env,
   1444                              cwd,
   1445                              startupinfo)
   1446 finally:
   1447     # Child is launched. Close the parent's copy of those pipe
   1448     # handles that only the child should have open.  You need
   (...)
   1451     # pipe will not close when the child process exits and the
   1452     # ReadFile will hang.

FileNotFoundError: [WinError 2] The system cannot find the file specified

The above exception was the direct cause of the following exception:

ExecutableNotFound                        Traceback (most recent call last)
Cell In [111], line 1
----> 1 mglearn.plots.plot_animal_tree()

File D:\Python\lib\site-packages\mglearn\plot_animal_tree.py:25, in plot_animal_tree(ax)
     23 mygraph.edge("2", "5", label="True")
     24 mygraph.edge("2", "6", label="False")
---> 25 mygraph.render("tmp")
     26 ax.imshow(imread("tmp.png"))
     27 ax.set_axis_off()

File D:\Python\lib\site-packages\graphviz\_tools.py:171, in deprecate_positional_args.<locals>.decorator.<locals>.wrapper(*args, **kwargs)
    162     wanted = ', '.join(f'{name}={value!r}'
    163                        for name, value in deprecated.items())
    164     warnings.warn(f'The signature of {func.__name__} will be reduced'
    165                   f' to {supported_number} positional args'
    166                   f' {list(supported)}: pass {wanted}'
    167                   ' as keyword arg(s)',
    168                   stacklevel=stacklevel,
    169                   category=category)
--> 171 return func(*args, **kwargs)

File D:\Python\lib\site-packages\graphviz\rendering.py:122, in Render.render(self, filename, directory, view, cleanup, format, renderer, formatter, neato_no_op, quiet, quiet_view, outfile, engine, raise_if_result_exists, overwrite_source)
    118 filepath = self.save(filename, directory=directory, skip_existing=None)
    120 args.append(filepath)
--> 122 rendered = self._render(*args, **kwargs)
    124 if cleanup:
    125     log.debug('delete %r', filepath)

File D:\Python\lib\site-packages\graphviz\_tools.py:171, in deprecate_positional_args.<locals>.decorator.<locals>.wrapper(*args, **kwargs)
    162     wanted = ', '.join(f'{name}={value!r}'
    163                        for name, value in deprecated.items())
    164     warnings.warn(f'The signature of {func.__name__} will be reduced'
    165                   f' to {supported_number} positional args'
    166                   f' {list(supported)}: pass {wanted}'
    167                   ' as keyword arg(s)',
    168                   stacklevel=stacklevel,
    169                   category=category)
--> 171 return func(*args, **kwargs)

File D:\Python\lib\site-packages\graphviz\backend\rendering.py:324, in render(engine, format, filepath, renderer, formatter, neato_no_op, quiet, outfile, raise_if_result_exists, overwrite_filepath)
    320     raise exceptions.FileExistsError(f'output file exists: {os.fspath(outfile)!r}')
    322 cmd += args
--> 324 execute.run_check(cmd,
    325                   cwd=filepath.parent if filepath.parent.parts else None,
    326                   quiet=quiet,
    327                   capture_output=True)
    329 return os.fspath(outfile)

File D:\Python\lib\site-packages\graphviz\backend\execute.py:84, in run_check(cmd, input_lines, encoding, quiet, **kwargs)
     82 except OSError as e:
     83     if e.errno == errno.ENOENT:
---> 84         raise ExecutableNotFound(cmd) from e
     85     raise
     87 if not quiet and proc.stderr:

ExecutableNotFound: failed to execute WindowsPath('dot'), make sure the Graphviz executables are on your systems' PATH

I searched multiple materials both online and offline, but nothing helped.

So, I highly appreciate if any member could give me a hand of how to sort this out.

Thank you so much and look forward to receiving your help.

user332276
  • 11
  • 3
  • A guess: you never seemed to have installed the "real" Graphviz. See https://stackoverflow.com/questions/73653801/problem-with-graphviz-executablenotfound-error/73654783#73654783 – sroush Nov 28 '22 at 16:17

0 Answers0