ImportError: Missing optional dependency 'xlrd'. Use pip or conda to install xlrd.
Third-person routing text. Fixes pandas read_excel failing with Missing optional dependency xlrd: install xlrd for legacy .xls files (openpyxl for .xlsx). Use when an agent hits this ImportError calling pd.read_excel. Not for other missing optional dependencies.
TL;DR: pandas needs the xlrd package to read legacy .xls files and it is not installed. Run pip install xlrd and re-run your read_excel call. For modern .xlsx files install openpyxl instead.
The error
ImportError: Missing optional dependency 'xlrd'. Use pip or conda to install xlrd.Fix it
- Install the Excel engine your file format needs:
pip install xlrdExpected: install completes.
- Re-run the read:
import pandas as pd
df = pd.read_excel("your_file.xls")
print(df.head())Expected: prints the first rows instead of raising.
- If your file is .xlsx (not .xls), install openpyxl instead:
pip install openpyxlWhen this applies
Use this when pd.read_excel raises the missing-xlrd message, which means the file is the legacy BIFF (.xls) format.
When it does not apply
If the error names openpyxl, pyxlsb, or odf, install that engine instead. If the file will not open even with the engine installed, the file itself may be corrupt.
Compatibility
All pandas versions. xlrd 2.x only reads .xls; it dropped .xlsx support, which is why .xlsx files need openpyxl.
Root cause
pandas keeps Excel engines as optional dependencies to stay light. It picks the engine from the file extension, and .xls maps to xlrd, which is not installed by default.
Edge cases
xlrd>=2.0 refuses .xlsx files with a clear error; do not fight it, use openpyxl. In locked-down environments, add xlrd to requirements so deploys do not regress.
Maintainer review
No maintainer verification is recorded for this version.
This records the version a maintainer checked. It does not assert that the version is the latest upstream release.