pandas-dev/pandas · error · ImportError

`Import {install_name}` failed. {extra} Use pip, conda, or y

Error message

`Import {install_name}` failed. {extra} Use pip, conda, or your preferred package management tool to install the {install_name} package.

What it means

Raised by import_optional_dependency (compat/_optional.py:107-163) when errors='raise' (the default) and the optional dependency cannot be imported via importlib.import_module. The message includes the `extra` hint string passed by the caller and instructs the user to install the package (mapping import names to PyPI names via INSTALL_MAPPING, e.g. 'bs4'->'beautifulsoup4').

Source

Thrown at pandas/compat/_optional.py:162

        None is returned when the package is not found and `errors`
        is False, or when the package's version is too old and `errors`
        is ``'warn'`` or ``'ignore'``.
    """
    assert errors in {"warn", "raise", "ignore"}

    package_name = INSTALL_MAPPING.get(name)
    install_name = package_name if package_name is not None else name

    msg = (
        f"`Import {install_name}` failed. {extra} "
        f"Use pip, conda, or your preferred package management tool "
        f"to install the {install_name} package."
    )
    try:
        module = importlib.import_module(name)
    except ImportError as err:
        if errors == "raise":
            raise ImportError(msg) from err
        return None

    # Handle submodules: if we have submodule, grab parent module from sys.modules
    parent = name.split(".", maxsplit=1)[0]
    if parent != name:
        install_name = parent
        module_to_get = sys.modules[install_name]
    else:
        module_to_get = module
    minimum_version = min_version if min_version is not None else VERSIONS.get(parent)
    if minimum_version:
        version = get_version(module_to_get)
        if version and Version(version) < Version(minimum_version):
            msg = (
                f"Pandas requires version '{minimum_version}' or newer of '{parent}' "
                f"(version '{version}' currently installed)."
            )
            if errors == "warn":

View on GitHub (pinned to 71959b8cb9)

Solutions

  1. Install the named package: pip install <install_name> (the error gives the correct PyPI name).
  2. If you can't install it, use errors='ignore' when calling import_optional_dependency yourself (pandas-internal callers don't expose this, so use a different engine/format).
  3. For I/O, switch to a built-in engine/format (e.g. read_excel engine='openpyxl' is also optional; use to_csv/to_pickle which need no optional deps).
  4. Add the relevant pandas extra: pip install 'pandas[parquet]' or 'pandas[html]'.

Example fix

# before — AttributeError/ImportError on to_parquet
df.to_parquet('out.parquet')  # pyarrow/fastparquet missing

# after
# shell: pip install pyarrow
df.to_parquet('out.parquet')
Defensive patterns

Strategy: fallback

Validate before calling

from pandas.compat._optional import import_optional_dependency
mod = import_optional_dependency('pyarrow', errors='ignore')
if mod is None:
    # feature unavailable — use a fallback path/engine
    use_arrow = False

Try / catch

try:
    import_optional_dependency('pyarrow', 'pyarrow is required for Arrow dtypes')
    HAS_PYARROW = True
except ImportError:
    HAS_PYARROW = False

Prevention

When it happens

Trigger: pandas internally calls import_optional_dependency('pyarrow', 'pyarrow is required for ...') when you use parquet/or Arrow-backed dtypes without pyarrow installed. Same path fires for read_html's lxml/bs4, read_excel's openpyxl/odf, HDFStore's tables, SQL's sqlalchemy, etc. Passing errors='warn' or 'ignore' returns None instead.

Common situations: Using a pandas I/O function (to_parquet, read_html, read_excel with a non-xlsx engine, to_sql, HDFStore) in an environment where the optional backend isn't installed; CI with a slim pandas install missing extras; a fresh virtualenv with only pandas.

Related errors


AI-assisted analysis of pandas-dev/pandas@71959b8cb9 (2026-08-07). Data as JSON: /api/errors/b1d2a6154ac2640d. Report an issue: GitHub.