diff --git a/doc/source/whatsnew/v0.21.0.txt b/doc/source/whatsnew/v0.21.0.txt index 42174c228ef3c..1b70c2d6104d7 100644 --- a/doc/source/whatsnew/v0.21.0.txt +++ b/doc/source/whatsnew/v0.21.0.txt @@ -115,6 +115,7 @@ Other Enhancements - :func:`DataFrame.items` and :func:`Series.items` is now present in both Python 2 and 3 and is lazy in all cases (:issue:`13918`, :issue:`17213`) - :func:`Styler.where` has been implemented. It is as a convenience for :func:`Styler.applymap` and enables simple DataFrame styling on the Jupyter notebook (:issue:`17474`). - :func:`MultiIndex.is_monotonic_decreasing` has been implemented. Previously returned ``False`` in all cases. (:issue:`16554`) +- :func:`read_excel` raises ``ImportError`` with better message if ``xlrd`` is not installed. (:issue:`17613`) .. _whatsnew_0210.api_breaking: diff --git a/pandas/io/excel.py b/pandas/io/excel.py index 5db4603c37be0..faafdba435ff2 100644 --- a/pandas/io/excel.py +++ b/pandas/io/excel.py @@ -239,12 +239,17 @@ class ExcelFile(object): def __init__(self, io, **kwds): - import xlrd # throw an ImportError if we need to + err_msg = "Install xlrd >= 0.9.0 for Excel support" - ver = tuple(map(int, xlrd.__VERSION__.split(".")[:2])) - if ver < (0, 9): # pragma: no cover - raise ImportError("pandas requires xlrd >= 0.9.0 for excel " - "support, current version " + xlrd.__VERSION__) + try: + import xlrd + except ImportError: + raise ImportError(err_msg) + else: + ver = tuple(map(int, xlrd.__VERSION__.split(".")[:2])) + if ver < (0, 9): # pragma: no cover + raise ImportError(err_msg + + ". Current version " + xlrd.__VERSION__) # could be a str, ExcelFile, Book, etc. self.io = io