[PYTHON] ImportError: Missing optional dependency'xlrd'. Install xlrd> = 1.0.0 for Excel support Use pip or conda to install xlrd.

--Environment --macOS Catalina version 10.15.7 - Python 3.8.5 - pandas 1.1.3

Event: I got angry when I tried to connect Pandas

Traceback (most recent call last):
  File "/Users/ponsuke/tryPython/main.py", line 7, in <module>
    book = pd.read_excel(excel_file, sheet_name=None, header=None)
  File "/Users/ponsuke/tryPython/venv/lib/python3.8/site-packages/pandas/util/_decorators.py", line 296, in wrapper
    return func(*args, **kwargs)
  File "/Users/ponsuke/tryPython/venv/lib/python3.8/site-packages/pandas/io/excel/_base.py", line 304, in read_excel
    io = ExcelFile(io, engine=engine)
  File "/Users/ponsuke/tryPython/venv/lib/python3.8/site-packages/pandas/io/excel/_base.py", line 867, in __init__
    self._reader = self._engines[engine](self._io)
  File "/Users/ponsuke/tryPython/venv/lib/python3.8/site-packages/pandas/io/excel/_xlrd.py", line 21, in __init__
    import_optional_dependency("xlrd", extra=err_msg)
  File "/Users/ponsuke/tryPython/venv/lib/python3.8/site-packages/pandas/compat/_optional.py", line 110, in import_optional_dependency
    raise ImportError(msg) from None
ImportError: Missing optional dependency 'xlrd'. Install xlrd >= 1.0.0 for Excel support Use pip or conda to install xlrd.

Process finished with exit code 1

main.py


import pandas as pd

# ...abridgement...
if __name__ == '__main__':
    excel_file = 'Book.xlsx'
    book = pd.read_excel(excel_file, sheet_name=None, header=None)

Cause: Pandas requires xlrd but doesn't have it installed

In order to read the Excel file, you also need to install the xlrd package. Reading and writing Excel using Python Pandas | Earl Effect

Action: Install xlrd

% pip install xlrd
Collecting xlrd
  Downloading xlrd-1.2.0-py2.py3-none-any.whl (103 kB)
     |████████████████████████████████| 103 kB 3.0 MB/s 
Installing collected packages: xlrd
Successfully installed xlrd-1.2.0

Recommended Posts

ImportError: Missing optional dependency'xlrd'. Install xlrd> = 1.0.0 for Excel support Use pip or conda to install xlrd.
"Import Error: Install xlrd> = 0.9.0 for Excel support" error in Pandas. Resolved by changing to use openpyxl
Install python on xserver to use pip
Install tweepy with pip and use it for API 1.1