Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
guifeliper opened this issue Feb 15, 2019 · 16 comments
Open

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

guifeliper opened this issue Feb 15, 2019 · 16 comments

Comments

@guifeliper
Copy link

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.
@jyoz90
Copy link

jyoz90 commented Feb 21, 2019

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

@guifeliper
Copy link
Author

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

@vlavorini
Copy link

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

@sviperm
Copy link

sviperm commented Feb 29, 2020

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

@tanjhysj0
Copy link

thanks

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

@calvin272m
Copy link

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.

@mikechen66
Copy link

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

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

@forumasisten
Copy link

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

ThankYou!!!!!!!!!!

@rosefun
Copy link

rosefun commented Aug 6, 2020

What about Red Hat system?

@bo-maxwell-stevens
Copy link

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

@hpl002
Copy link

hpl002 commented Dec 21, 2020

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..

@jorge-cue
Copy link

What about Red Hat system?

This worked for me on Fedora 36

sudo dnf install graphviz

@haodong2000
Copy link

sudo apt install graphviz

thanks!!

@Alrabef
Copy link

Alrabef commented Apr 15, 2023

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

@charleschen0611
Copy link

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!

@himra13
Copy link

himra13 commented Aug 22, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests