Skip to content

Commit

Permalink
import pydot, improve error messages about pydot and GraphViz, bu…
Browse files Browse the repository at this point in the history
…mp to `pydot >= 1.2.4` (#9904)

* REL: bump to `pydot >= 1.2.4` in `extras_require`

* MAI: import pydot (as required in `extras_require`)

* MAI: refine error messages for `pydot` and GraphViz

distinguish between absence of `pydot` and failure to find
the executables of GraphViz in the $PATH.

* DEV: ignore `.pytest_cache`
  • Loading branch information
johnyf authored and fchollet committed Apr 11, 2018
1 parent 12cf652 commit 946a3b3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
1 change: 1 addition & 0 deletions .gitignore
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
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.')

This comment has been minimized.

Copy link
@Planck35

Planck35 Apr 12, 2018

Hello, I got a problem about it
I installed the graphviz package using pip install graphviz in Windows.
and i installed the graphviz-2.38.msi from https://www.graphviz.org
also, I added the PATH: C:\Program Files (x86)\Graphviz2.38\bin with a name Graphviz2.38.

So, why it still couldn't work, and how do you ensure it is executable in the $PATH

I am a fresh man, maybe you can give me some intuition
Thanks 👍



def model_to_dot(model,
Expand Down
2 changes: 1 addition & 1 deletion setup.py
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

0 comments on commit 946a3b3

Please sign in to comment.