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

import pydot, improve error messages about pydot and GraphViz, bump to pydot >= 1.2.4 #9904

Merged
merged 4 commits into from
Apr 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ examples/img/*
# test-related
.coverage
.cache
.pytest_cache

# developer environments
.idea
Expand Down
31 changes: 15 additions & 16 deletions keras/utils/vis_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,30 @@

import os

# `pydot` is an optional dependency,
# see `extras_require` in `setup.py`.
try:
# pydot-ng is a fork of pydot that is better maintained.
import pydot_ng as pydot
import pydot
except ImportError:
# pydotplus is an improved version of pydot
try:
import pydotplus as pydot
except ImportError:
# Fall back on pydot if necessary.
try:
import pydot
except ImportError:
pydot = None
pydot = None


def _check_pydot():
"""Raise errors if `pydot` or GraphViz unavailable."""
if pydot is None:
raise ImportError(
'Failed to import `pydot`. '
'Please install `pydot`. '
'For example with `pip install pydot`.')
try:
# Attempt to create an image of a blank graph
# to check the pydot/graphviz installation.
pydot.Dot.create(pydot.Dot())
except Exception:
# pydot raises a generic Exception here,
# so no specific class can be caught.
raise ImportError('Failed to import pydot. You must install pydot'
' and graphviz for `pydotprint` to work.')
except OSError:
raise OSError(
'`pydot` failed to call GraphViz.'
'Please install GraphViz (https://www.graphviz.org/) '
'and ensure that its executables are in the $PATH.')


def model_to_dot(model,
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
'pyyaml',
'h5py'],
extras_require={
'visualize': ['pydot>=1.2.0'],
'visualize': ['pydot>=1.2.4'],
'tests': ['pytest',
'pytest-pep8',
'pytest-xdist',
Expand Down