Skip to content
This repository has been archived by the owner on Jul 2, 2021. It is now read-only.

Dynamically import matplotlib.pyplot #519

Merged
merged 2 commits into from
Feb 27, 2018
Merged
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
10 changes: 7 additions & 3 deletions chainercv/extensions/vis_report/detection_vis_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
from chainercv.visualizations.vis_bbox import vis_bbox

try:
from matplotlib import pyplot as plot
import matplotlib # NOQA
_available = True

except ImportError:
except (ImportError, TypeError):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there any cases that TypeError is raised?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copied it from Chainer.

TypeError is sometimes called when backend is not imported properly.

related

chainer/chainer#2482

https://stackoverflow.com/questions/31328436/typeerror-constructor-returned-null-while-importing-pyplot-in-ssh

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see.

_available = False


Expand Down Expand Up @@ -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'):
Expand Down