How To Fix Error Pandas Cannot Open An Excel xlsx File

In [1]:
import pandas as pd

Let us try opening a XLSX file.

In [ ]:
pd.read_excel('test.xlsx')

I got following error...

XLRDError: Excel xlsx file; not supported

In [3]:
pd.__version__
Out[3]:
'1.1.5'

Well there are couple of ways to fix this problem.

With Pandas < 1.2 version, using engine='openpyxl' option fixes the problem.

Use Option engine='openpyxl'

In [4]:
df = pd.read_excel('test.xlsx',engine='openpyxl')
In [5]:
df.size
Out[5]:
36

Upgrade Pandas to 1.2 Version

Another way is to upgrade pandas to >= 1.2 version.

To install pandas, make sure you have Python >= 3.7 version installed.

once you have correct version of Python installed. Just install pandas using pip.

pip install pandas==1.2.4

Now pd.read_excel will just work fine.

In [ ]:
df = pd.read_excel('test.xlsx')