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

Added support for new pydot versions to fix find_graphviz error #6398

Merged
merged 4 commits into from
Apr 26, 2017

Conversation

pnb
Copy link
Contributor

@pnb pnb commented Apr 25, 2017

I was having difficulties with the keras.utils.plot_model function, specifically that pydot no longer supports the find_graphviz function, and installing pydot-ng instead does not seem to fix it. This pull request should solve issue #3210.

try:
if hasattr(pydot, 'find_graphviz'):
if not pydot.find_graphviz():
raise ImportError()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs an error message explaining what went wrong and how to fix it (like below).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After experimenting more it seems like this isn't even needed anymore, so I removed it.

if not pydot.find_graphviz():
raise ImportError()
else:
pydot.Dot.create(pydot.Dot())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this statement for? A comment would be helpful.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

raise ImportError()
else:
pydot.Dot.create(pydot.Dot())
except:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No catch-all exceptions. You should catch a specific class.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem with this is that pydot raises a generic exception if it can't find dot, so there is no specific class. One alternative might be to not checking the dot installation at all, but that produces a less helpful error message that doesn't mention graphviz specifically.

try:
# Attempt to create an image of a blank graph to check the pydot/graphviz installation.
pydot.Dot.create(pydot.Dot())
except:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again: you should only except a specific Exception class.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is not a specific Exception class in this situation. pydot raises a generic Exception (pydot source).

Copy link
Collaborator

@fchollet fchollet Apr 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wow... In this case let's catch the exception, add a comment on why we use Exception, and check that the exception message is what we expect. raise otherwise.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, never mind what I said, it will be safer to just catch Exception. Do add a comment on why we do this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For what it's worth I will probably also try submit a pull request to pyplot to raise a more appropriate exception.

@johnyf
Copy link
Contributor

johnyf commented Apr 26, 2017

Please see #5313 (comment).

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

Successfully merging this pull request may close these issues.

3 participants