Last updated: Apr 10, 2024
Reading timeยท3 min
The error "xlrd.biffh.XLRDError: Excel xlsx file; not supported" occurs
because the package xlrd
now only supports .xls
files.
To solve the error, upgrade your version of pandas
, install the openpyxl
module and use it to read excel files instead.
File "C:\python\lib\site-packages\xlrd\__init__.py", line 174, in open_workbook raise XLRDError(FILE_FORMAT_DESCRIPTIONS[file_format]+'; not supported') xlrd.biffh.XLRDError: Excel xlsx file; not supported
xlrd
only supports old-style .xls
files because of some security implications.As shown in the docs, the xlrd
library will no longer read anything other than
.xls
files.
pandas
and install openpyxl
To resolve the issue:
pip install pandas --upgrade pip3 install pandas --upgrade python -m pip install pandas --upgrade python3 -m pip install pandas --upgrade py -m pip install pandas --upgrade # ๐๏ธ For Jupyter Notebook !pip install pandas --upgrade
pip install openpyxl --upgrade pip3 install openpyxl --upgrade python -m pip install openpyxl --upgrade python3 -m pip install openpyxl --upgrade py -m pip install openpyxl --upgrade # ๐๏ธ For Jupyter Notebook !pip install openpyxl --upgrade
engine
keyword argument to openpyxl
in the call to the
read_excel()
method.import pandas as pd df = pd.read_excel( 'example.xlsx', engine='openpyxl' ) print(df)
The code sample assumes that you have an example.xlsx
file in the same
directory.
Name Salary 0 Alice 100 1 Bobby 75 2 Carl 150
Note that openpyxl
does not support the old .xls
file format.
If you need to read a .xls
file, you have to use xlrd
instead.
Alternatively, you can convert the file to .xlsx
.
Assuming you have a file called another.xls
, you can set the engine to xlrd
to read it.
import pandas as pd df = pd.read_excel( 'another.xls', engine='xlrd' ) print(df)
If the suggestion of upgrading pandas
and using openpyxl
didn't work, you
could try to downgrade xlrd
to the last version that supports reading .xlsx
files.
xlrd
, note that this has security implications because files with the .xslx
extension may contain scripts.More recent versions of pandas
also throw an error if you have version 1.X
of xlrd
installed.
1.X
of xlrd
(NOT RECOMMENDED)If you are OK with the security risks of using xlrd
version 1.X
, run the
following command.
pip uninstall xlrd pip install xlrd==1.2.0 pip3 uninstall xlrd pip3 install xlrd==1.2.0
If you get an error that ImportError: Pandas requires version '2.X' or newer
of 'xlrd' (version '1.2.0' currently installed), upgrade your version of
xlrd
and pandas
and use the openpyxl
package to read .xlsx
files
instead.
pip install pandas xlrd --upgrade pip3 install pandas xlrd --upgrade python -m pip install pandas xlrd --upgrade python3 -m pip install pandas xlrd --upgrade py -m pip install pandas xlrd --upgrade # ๐๏ธ For Jupyter Notebook !pip install pandas xlrd --upgrade
If you don't have openpyxl
installed, run the following command.
pip install openpyxl --upgrade pip3 install openpyxl --upgrade python -m pip install openpyxl --upgrade python3 -m pip install openpyxl --upgrade py -m pip install openpyxl --upgrade # ๐๏ธ For Jupyter Notebook !pip install openpyxl --upgrade
engine
keyword argument to openpyxl
Explicitly set the engine
keyword argument to openpyxl
in the call to the
pandas.read_excel()
method.
import pandas as pd df = pd.read_excel( 'example.xlsx', engine='openpyxl' ) print(df)
Files with .xls
and .xlsx
extensions are distinct.
If a file has a .xlsx
extension, then it might contain executable scripts.
The xlrd
library no longer supports files with .xlsx
extensions because of
the security implications around reading files that might contain executable
scripts.
The openpyxl
module should be used to read files with .xlsx
extension.
import pandas as pd df = pd.read_excel( 'example.xlsx', engine='openpyxl' ) print(df)
On the other hand, the openpyxl
module doesn't support files with .xls
extension.
If you need to read a file with a .xls
extension, use the xlrd
module
instead.
import pandas as pd df = pd.read_excel( 'another.xls', engine='xlrd' ) print(df)
Make sure the file you are trying to read hasn't been named using the wrong
extension (.xlsx
vs .xls
).
To solve the error error "xlrd.biffh.XLRDError: Excel xlsx file; not supported":
pandas
module.openpyxl
module.engine
keyword argument to openpyxl
in the call to the
pandas.read_excel()
method.