Skip to content

Commit

Permalink
more explicit error message when matplotlib backend fails
Browse files Browse the repository at this point in the history
  • Loading branch information
m-vdb committed Apr 28, 2021
1 parent 9dfc16c commit b9ac7a3
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions rasa/utils/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,19 @@

def _fix_matplotlib_backend() -> None:
"""Tries to fix a broken matplotlib backend."""
try:
backend = matplotlib.get_backend()
except Exception: # skipcq:PYL-W0703
logger.error(
"Cannot retrieve Matplotlib backend, likely due to a compatibility "
"issue with system dependencies. Please refer to the documentation: "
"https://matplotlib.org/stable/tutorials/introductory/usage.html#backends"
)
raise

# At first, matplotlib will be initialized with default OS-specific
# available backend
if matplotlib.get_backend() == "TkAgg":
if backend == "TkAgg":
try:
# on OSX sometimes the tkinter package is broken and can't be imported.
# we'll try to import it and if it fails we will use a different backend
Expand All @@ -28,7 +38,7 @@ def _fix_matplotlib_backend() -> None:
matplotlib.use("agg")

# if no backend is set by default, we'll try to set it up manually
elif matplotlib.get_backend() is None: # pragma: no cover
elif backend is None: # pragma: no cover
try:
# If the `tkinter` package is available, we can use the `TkAgg` backend
import tkinter # skipcq: PYL-W0611
Expand Down

0 comments on commit b9ac7a3

Please sign in to comment.