From 6297d47ff40385b830c92272e311caafaf1c8268 Mon Sep 17 00:00:00 2001 From: Yusuke Niitani Date: Tue, 6 Feb 2018 14:49:55 +0900 Subject: [PATCH 1/2] dynamically import matplotlib.pyplot --- .../extensions/vis_report/detection_vis_report.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/chainercv/extensions/vis_report/detection_vis_report.py b/chainercv/extensions/vis_report/detection_vis_report.py index 513982bf4c..90b4529729 100644 --- a/chainercv/extensions/vis_report/detection_vis_report.py +++ b/chainercv/extensions/vis_report/detection_vis_report.py @@ -7,10 +7,10 @@ from chainercv.visualizations.vis_bbox import vis_bbox try: - from matplotlib import pyplot as plot + import matplotlib _available = True -except ImportError: +except (ImportError, TypeError): _available = False @@ -89,7 +89,11 @@ def available(): return _available def __call__(self, trainer): - if not _available: + if _available: + # Dynamically import pyplot so that the backend of matplotlib + # can be configured after importing chainercv. + import matplotlib.pyplot as plot + else: return if hasattr(self.iterator, 'reset'): From d636242a86c32000b7006ac95ea570a638c5fe27 Mon Sep 17 00:00:00 2001 From: Yusuke Niitani Date: Tue, 6 Feb 2018 15:05:57 +0900 Subject: [PATCH 2/2] flake8 --- chainercv/extensions/vis_report/detection_vis_report.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chainercv/extensions/vis_report/detection_vis_report.py b/chainercv/extensions/vis_report/detection_vis_report.py index 90b4529729..c213919585 100644 --- a/chainercv/extensions/vis_report/detection_vis_report.py +++ b/chainercv/extensions/vis_report/detection_vis_report.py @@ -7,7 +7,7 @@ from chainercv.visualizations.vis_bbox import vis_bbox try: - import matplotlib + import matplotlib # NOQA _available = True except (ImportError, TypeError):