diff --git a/lib/matplotlib/cbook/__init__.py b/lib/matplotlib/cbook/__init__.py index 87cfe7fd4d84..73c48fa728f6 100644 --- a/lib/matplotlib/cbook/__init__.py +++ b/lib/matplotlib/cbook/__init__.py @@ -8,7 +8,6 @@ import six from six.moves import xrange, zip -import bz2 import collections import contextlib import datetime @@ -478,6 +477,9 @@ def to_filehandle(fname, flag='rU', return_opened=False, encoding=None): flag = flag.replace('U', '') fh = gzip.open(fname, flag) elif fname.endswith('.bz2'): + # python may not be complied with bz2 support, + # bury import until we need it + import bz2 # get rid of 'U' in flag for bz2 files flag = flag.replace('U', '') fh = bz2.BZ2File(fname, flag)