# How to fix ImportError: Missing optional dependency 'openpyxl'. Use pip or conda to install openpyxl.

Install the Excel engine: `python -m pip install openpyxl`. pandas deliberately does not bundle Excel readers; `read_excel` on an .xlsx file needs openpyxl installed in the same environment. Use the exact same python/pip pair (`python -m pip`) so it lands in the right env.

## The exact error

```text
ImportError: Missing optional dependency 'openpyxl'. Use pip or conda to install openpyxl.
```

## Fix it

1. Run `python -m pip install openpyxl`.
   Expected: pip reports Successfully installed openpyxl

2. Retry `pd.read_excel('file.xlsx')`.
   Expected: returns a DataFrame, no ImportError

3. For legacy .xls files you need xlrd instead: `python -m pip install xlrd`.
   Expected: read_excel works on .xls

## When this applies

pd.read_excel / ExcelFile / to_excel on .xlsx raises Missing optional dependency 'openpyxl'

## When this does NOT apply

the file itself is missing (FileNotFoundError) or corrupt (BadZipFile)

## Versions

pandas >= 1.0 reading .xlsx

## Why it happens

Excel IO engines are optional dependencies; pandas raises a helpful ImportError telling you which one to install.

## Edge cases

xlrd >= 2.0 dropped .xlsx support, so do not 'fix' this by installing xlrd for an .xlsx file.
