Skip to content

Better Message for xlrd Dependencies #28546

Closed
@WillAyd

Description

@WillAyd

Right now if you don't have xlrd installed and use read_excel without specifying the engine keyword you get the following message:

>>> pd.read_excel("test.xlsx")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/williamayd/.pyenv/versions/3.7.2/lib/python3.7/site-packages/pandas/util/_decorators.py", line 208, in wrapper
    return func(*args, **kwargs)
  File "/Users/williamayd/.pyenv/versions/3.7.2/lib/python3.7/site-packages/pandas/io/excel/_base.py", line 310, in read_excel
    io = ExcelFile(io, engine=engine)
  File "/Users/williamayd/.pyenv/versions/3.7.2/lib/python3.7/site-packages/pandas/io/excel/_base.py", line 819, in __init__
    self._reader = self._engines[engine](self._io)
  File "/Users/williamayd/.pyenv/versions/3.7.2/lib/python3.7/site-packages/pandas/io/excel/_xlrd.py", line 20, in __init__
    import_optional_dependency("xlrd", extra=err_msg)
  File "/Users/williamayd/.pyenv/versions/3.7.2/lib/python3.7/site-packages/pandas/compat/_optional.py", line 93, in import_optional_dependency
    raise ImportError(message.format(name=name, extra=extra)) from None
ImportError: Missing optional dependency 'xlrd'. Install xlrd >= 1.0.0 for Excel support Use pip or conda to install xlrd.

This is in spite of the fact that the user may have openpyxl installed and could do something like pd.read_excel(..., engine="openpyxl") to get the same code to work

Two issues need to be addressed here:

  • The default read_excel call with no engine argument should fall back to openpyxl, if installed
  • The default error message should direct the user to install openpyxl first and foremost, as xlrd is unmaintained

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions