votes up 4

No engine for filetype: '(ext)'

Package:
pandas
github stars 30911
Exception Class:
ValueError

Raise code

                    ext = "xlsx"

                try:
                    engine = config.get_option(f"io.excel.{ext}.writer", silent=True)
                    if engine == "auto":
                        engine = get_default_engine(ext, mode="writer")
                except KeyError as err:
                    raise ValueError(f"No engine for filetype: '{ext}'") from err

            if engine == "xlwt":
                xls_config_engine = config.get_option(
                    "io.excel.xls.writer", silent=True
                )
                # Don't warn a 2nd time if user has changed the default engine for xls
                if xls_config_engine != "xlwt":
😲  Walkingbet is Android app that pays you real bitcoins for a walking. Withdrawable real money bonus is available now, hurry up! 🚶

Ways to fix

votes up 1 votes down

Steps to reproduce:

$ mkdir test-pandas

$ cd test-pandas

$ pipenv shell

$ pipenv install pandas

Run the below code to reproduce:

import pandas as pd

df = pd.DataFrame([["ABC", "XYZ"]], columns=["Foo", "Bar"])
with pd.ExcelWriter("filename.txt") as writer:
  df.to_excel(writer)

The above code generates the following exception:

---------------------------------------------------------------------------
OptionError                               Traceback (most recent call last)
/usr/local/lib/python3.7/dist-packages/pandas/io/excel/_base.py in __new__(cls, path, engine, **kwargs)
    632                 try:
--> 633                     engine = config.get_option(f"io.excel.{ext}.writer")
    634                     if engine == "auto":

OptionError: "No such keys(s): 'io.excel.txt.writer'"
The above exception was the direct cause of the following exception:

ValueError                                Traceback (most recent call last)
/usr/local/lib/python3.7/dist-packages/pandas/io/excel/_base.py in __new__(cls, path, engine, **kwargs)
    635                         engine = _get_default_writer(ext)
    636                 except KeyError as err:
--> 637                     raise ValueError(f"No engine for filetype: '{ext}'") from err
    638             cls = get_writer(engine)
    639 

ValueError: No engine for filetype: 'txt'


Fixed version of code:

import pandas as pd

df = pd.DataFrame([["ABC", "XYZ"]], columns=["Foo", "Bar"])
with pd.ExcelWriter("filename.xlsx") as writer: # xlsx file type which is file extension for Microsoft Excel Open XML Spreadsheet
  df.to_excel(writer)

Explanation:

The filetype we gave i.e. 'txt' file there was no engine found. To fix it make sure we provide a valid filetype.

Jun 19, 2021 umangtaneja98 answer

Add a possible fix

Please authorize to post fix