Pandas: how to make openpyxl the default engine for all read_excel operations?

Since read_exceldefault engine xlrd has been deprecated in newer pandas releases, how do I make openpyxl the default engine of all my pd.read_excel calls?

Now, if I update pandas, I must put the parameter engine="openpyxl" in all my pd.read_excel calls. It looks unnecessary.


It's easy! You can do it by changing the default values of the method by going to the _base.py inside the environment's pandas folder. You can find it as follows:

import pandas as pd
print(pd.__file__)

Once in the pandas folder, dive into the folder io > excel > _base.py

Open the file and find

def read_excel(...)

You will find the default value for engine. Change it to 'openpyxl'

If you're using vscode, simply right click on the instance of the method .read_excel and press F12, or go to the definition and change it right away.


If you're using pandas version 1.1.5 or other new version this might help:

Run print(pd.__file__) to see where your pandas library is stored. Usually, the file path would end in "Lib\site-packages\pandas". Then, open folder "io" and folder "excel" right after. You will find there the "_base.py" file.

Look for the def __init__. You will find there the default engine to read Excel files. It should be on line 849. I should read:

if engine is None:
    engine = "openpyxl"