When you read an excel file with .xlsx extension using the pandas function read_excel() following error is thrown :
XLRDError: Excel xlsx file; not supported
Firstly, let’s understand what causes the error.
Table of Contents
Why is “XLRDError: Excel xlsx file; not supported” seen?
XLRD package has stopped its support for the excel files with the xlsx extension. This change has been made owing to a potential security risk.
This is in effect from xlrd version 2.o in Python 3.9+.
If you want to get rid of the error, you can try one of the following fixes.
Fix 1: Use openpyxl package
Firstly, let us see what the Official Pandas Site has to say,
Install openpyxl package
1. Open Command Prompt/Terminal.
2. To install openpyxl using pip enter the below command.
pip install openpyxl
Note: If you are using Python3, change pip to pip3
For pandas to version 1.2+
From Pandas version 1.2 and beyond, if you have an openpyxl package installed in your system, in most cases, pandas automatically use the openpyxl engine to read xlsx.
1. Open the Command Prompt/ Terminal.
2. Enter the below command to update pandas to the latest release.
pip install --upgrade pandas
Note: If you are using Python3, change pip to pip3
If you are still seeing the error, specify the engine explicitly using the below method.
For pandas versions lesser than 1.2
If you are using, pandas version less than 1.2, then you have to explicitly specify the engine within read_excel() function.
pd.read_excel(<path_to_excel_file>, engine='openpyxl')
Fix 2: Install older version xlrd
Note: This fix exposes you to security issues. Please proceed at your own risk.
The xlrd version 1.2.0 supports the use of xlsx file extensions.
To install an older version of xlrd in your system, do the following.
1. Open Command Prompt/ Terminal.
2. Enter the below command :
pip install xlrd==1.2.0
Note: If you are using Python3, change pip to pip3
Conclusion
We have discussed what causes the error, “XLRDError: Excel xlsx file; not supported” in Python while reading the files using the read_excel() function. The article also tells us about the ways to fix the error.
We hope this article has been informative. Kindly comment and let us know if you found this article helpful.