From e77dcf63bf3e1990207056874cf42bc9e74f1bf4 Mon Sep 17 00:00:00 2001 From: Phil Elson Date: Mon, 27 Sep 2021 14:40:54 +0200 Subject: [PATCH] Guard against ipympl.backend_nbagg being imported outside of an IPython environment. Closes https://github.com/matplotlib/ipympl/issues/363. --- ipympl/backend_nbagg.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ipympl/backend_nbagg.py b/ipympl/backend_nbagg.py index aa1882d8..d1650564 100644 --- a/ipympl/backend_nbagg.py +++ b/ipympl/backend_nbagg.py @@ -428,4 +428,5 @@ def flush_figures(): ip = get_ipython() -ip.events.register('post_execute', flush_figures) +if ip is not None: + ip.events.register('post_execute', flush_figures)