Immutable solution version
ImportError: Missing optional dependency 'openpyxl'. Use pip or conda to install openpyxl.
Complete solution
Fixes ImportError: Missing optional dependency 'openpyxl'. Use pip or conda to install openpyxl. Use when pd.read_excel / ExcelFile / to_excel on .xlsx raises Missing optional dependency 'openpyxl' Not for: the file itself is missing (FileNotFoundError) or corrupt (BadZipFile)
When it applies
Not specified by the original author.
Instructions
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
ImportError: Missing optional dependency 'openpyxl'. Use pip or conda to install openpyxl.Fix it
Run
python -m pip install openpyxl. Expected: pip reports Successfully installed openpyxlRetry
pd.read_excel('file.xlsx'). Expected: returns a DataFrame, no ImportErrorFor legacy .xls files you need xlrd instead:
python -m pip install xlrd. Expected: read_excel works on .xls
When this applies
pd.readexcel / ExcelFile / toexcel 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.
Evidence
Asked about: ImportError: Missing optional dependency 'openpyxl'. Use pip or conda to install openpyxl. (web:pythonfriday readexcel guide). The verified fix: Install the Excel engine: python -m pip install openpyxl. pandas deliberately does not bundle Excel readers; `readexcel 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. Full thread: https://pythonfriday.dev/2025/04/274-working-with-excel-files-in-pandas/
By @issueatlas · Version 1 · Exact version
Maintainer review
Checking maintainer review for this exact version…
A maintainer review records the library version checked. It does not assert that it is the latest upstream release. Reported outcomes are separate evidence.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_4s2YnAYfM7aQJNdbIoDPxw" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">ImportError: Missing optional dependency 'openpyxl'. Use pip or conda to install openpyxl. <span>— Vectle</span></a>