Data-Analysis icon indicating copy to clipboard operation
Data-Analysis copied to clipboard

Graphviz error No such file or directory: 'dot': 'dot'

Open guifeliper opened this issue 5 years ago • 16 comments

I have an error when I try to run the command

# Write graph to a png file
graph.write_png('tree.png');

The error bellow happens even if I have the tree.dot file and installed pip install graphviz

FileNotFoundError                         Traceback (most recent call last)
/usr/lib/python3.6/site-packages/pydot.py in create(self, prog, format, encoding)
   1914                 arguments=arguments,
-> 1915                 working_dir=tmp_dir,
   1916             )

/usr/lib/python3.6/site-packages/pydot.py in call_graphviz(program, arguments, working_dir, **kwargs)
    135         stdout=subprocess.PIPE,
--> 136         **kwargs
    137     )

/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)
    708                                 errread, errwrite,
--> 709                                 restore_signals, start_new_session)
    710         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)
   1343                             err_msg += ': ' + repr(err_filename)
-> 1344                     raise child_exception_type(errno_num, err_msg, err_filename)
   1345                 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:

FileNotFoundError                         Traceback (most recent call last)
<ipython-input-26-800bf34d174d> in <module>()
      1 # Write graph to a png file
----> 2 graph.write_png('tree.png');

/usr/lib/python3.6/site-packages/pydot.py in new_method(path, f, prog, encoding)
   1732                 self.write(
   1733                     path, format=f, prog=prog,
-> 1734                     encoding=encoding)
   1735             name = 'write_{fmt}'.format(fmt=frmt)
   1736             self.__setattr__(name, new_method)

/usr/lib/python3.6/site-packages/pydot.py in write(self, path, prog, format, encoding)
   1815                 f.write(s)
   1816         else:
-> 1817             s = self.create(prog, format, encoding=encoding)
   1818             with io.open(path, mode='wb') as f:
   1819                 f.write(s)

/usr/lib/python3.6/site-packages/pydot.py in create(self, prog, format, encoding)
   1920                 args[1] = '"{prog}" not found in path.'.format(
   1921                     prog=prog)
-> 1922                 raise OSError(*args)
   1923             else:
   1924                 raise

FileNotFoundError: [Errno 2] "dot" not found in path.

guifeliper avatar Feb 15 '19 13:02 guifeliper

Same error here. after i install pydot and graphviz, still getting the error. Any advise on how to solve this? Thanks!

jyoz90 avatar Feb 21 '19 10:02 jyoz90

@jyoz90 you need to download the binary as well, that worked for me. apk add --update --no-cache graphviz

guifeliper avatar Feb 21 '19 10:02 guifeliper

I confirm what @guifeliper wrote work also on MacOS: you have to install graphviz on the system (brew install graphviz) and not with Pip.

vlavorini avatar Jun 04 '19 15:06 vlavorini

I solved it by installing pydot and graphiz with command sudo apt install python-pydot python-pydot-ng graphviz ref

sviperm avatar Feb 29 '20 06:02 sviperm

thanks

我通过使用命令ref安装pydot和graphiz解决了它 sudo apt install python-pydot python-pydot-ng graphviz

tanjhysj0 avatar Mar 16 '20 23:03 tanjhysj0

FileNotFoundError Traceback (most recent call last) ~/opt/anaconda3/lib/python3.7/site-packages/pydot.py in create(self, prog, format, encoding) 1914 arguments=arguments, -> 1915 working_dir=tmp_dir, 1916 )

~/opt/anaconda3/lib/python3.7/site-packages/pydot.py in call_graphviz(program, arguments, working_dir, **kwargs) 135 stdout=subprocess.PIPE, --> 136 **kwargs 137 )

~/opt/anaconda3/lib/python3.7/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, text) 774 self._closed_child_pipe_fds = False --> 775 776 try:

~/opt/anaconda3/lib/python3.7/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) 1521 pass -> 1522 1523 try:

FileNotFoundError: [Errno 2] No such file or directory: 'dot': 'dot'

During handling of the above exception, another exception occurred:

FileNotFoundError Traceback (most recent call last) in ----> 1 plot_tree(regressionTree, ['Years','Hits'])

in plot_tree(estimator, features, class_names, filled) 11 precision = 2) 12 graph = pydot.graph_from_dot_data(dot_data.getvalue())[0] ---> 13 return Image(graph.create_png())

~/opt/anaconda3/lib/python3.7/site-packages/pydot.py in new_method(f, prog, encoding) 1721 """Refer to docstring of method create.""" 1722 return self.create( -> 1723 format=f, prog=prog, encoding=encoding) 1724 name = 'create_{fmt}'.format(fmt=frmt) 1725 self.setattr(name, new_method)

~/opt/anaconda3/lib/python3.7/site-packages/pydot.py in create(self, prog, format, encoding) 1920 args[1] = '"{prog}" not found in path.'.format( 1921 prog=prog) -> 1922 raise OSError(*args) 1923 else: 1924 raise

FileNotFoundError: [Errno 2] "dot" not found in path.

I 'brew install graphviz' , but still has this problem. what I did is following the introduction to statistic learning by python, before this code, there is a code to find the location of graphviz

find the location of graphviz so dot.exe is in the PATH

import os common_path = os.path.commonpath([path for path in os.environ["PATH"].split(';') if 'Anaconda' in path]) dot_path = os.path.join(common_path, 'Library', 'bin', 'graphviz') os.environ["PATH"] += os.pathsep + dot_path but my case is no 'Anaconda' capitalized A, I used 'anaconda' instead, that's all. Then I got the error message.

calvin272m avatar Apr 20 '20 14:04 calvin272m

While in the virtual environment, the following installation methods does not works

sudo apt install python-pydot python-pydot-ng graphviz

mikechen66 avatar Apr 26 '20 23:04 mikechen66

I solved it by installing pydot and graphiz with command sudo apt install python-pydot python-pydot-ng graphviz ref

ThankYou!!!!!!!!!!

forumasisten avatar May 11 '20 17:05 forumasisten

What about Red Hat system?

rosefun avatar Aug 06 '20 12:08 rosefun

This worked for me in virtual machine with anaconda: sudo apt install graphviz

bo-maxwell-stevens avatar Dec 09 '20 02:12 bo-maxwell-stevens

I confirm what @guifeliper wrote work also on MacOS: you have to install graphviz on the system (brew install graphviz) and not with Pip.

Any idea why this is needed?

Installing via homebrew simply installs the binary in /usr/local/Cellar as opposed to pip which installs in /usr/local/lib/python@version/site-packages.

Both are available on PATH so i struggle to see why there would be a difference, even though there definitely is..

hpl002 avatar Dec 21 '20 16:12 hpl002

What about Red Hat system?

This worked for me on Fedora 36

sudo dnf install graphviz

jorge-cue avatar Nov 07 '22 04:11 jorge-cue

sudo apt install graphviz

thanks!!

haodong2000 avatar Dec 26 '22 06:12 haodong2000

The solution using "brew install graphviz" works very fine after trying to do something in Python. Thankyou @guifeliper

Alrabef avatar Apr 15 '23 11:04 Alrabef

I confirm what @guifeliper wrote work also on MacOS: you have to install graphviz on the system (brew install graphviz) and not with Pip.

And the Homebrew command from @vlavorini works with Jupyter Notebook as well. Thanks!

charleschen0611 avatar Aug 21 '23 20:08 charleschen0611

I confirm that this works on macbook. Thank you so much

I confirm what @guifeliper wrote work also on MacOS: you have to install graphviz on the system (brew install graphviz) and not with Pip.

himra13 avatar Aug 22 '23 10:08 himra13