pola-rs/polars · error

{prefix}'{module_name}'{suffix}. Please install using the co

Error message

{prefix}'{module_name}'{suffix}.
Please install using the command `pip install {module_root}`.

What it means

Raised by polars' internal `_import_package` helper: a function that requires an optional third-party library calls import_module() and, on ImportError, re-raises ModuleNotFoundError with the exact module name and the `pip install <root-package>` command that provides it. Like the proxy-module error, it fires only when the optional code path actually runs, and it always tells you the root package to install.

Source

Thrown at py-polars/src/polars/_dependencies.py:298

    ...     err_prefix="super-important package",
    ... )  # doctest: +SKIP
    ImportError: super-important package 'definitely_a_real_module' not installed.
    Please install it using the command `pip install definitely_a_real_module`.
    """
    from polars._utils.various import parse_version
    from polars.exceptions import ModuleUpgradeRequiredError

    module_root = module_name.split(".", 1)[0]
    try:
        module = import_module(module_name)
    except ImportError:
        prefix = f"{err_prefix.strip(' ')} " if err_prefix else ""
        suffix = f" {err_suffix.strip(' ')}" if err_suffix else ""
        err_message = f"{prefix}'{module_name}'{suffix}.\n" + (
            install_message
            or f"Please install using the command `pip install {module_root}`."
        )
        raise ModuleNotFoundError(err_message) from None

    if min_version:
        min_version = parse_version(min_version)
        mod_version = parse_version(module.__version__)
        if mod_version < min_version:
            msg = (
                f"{min_err_prefix} {module_root} "
                f"{'.'.join(str(v) for v in min_version)} or higher"
                f" (found {'.'.join(str(v) for v in mod_version)})"
            )
            raise ModuleUpgradeRequiredError(msg)

    return module


__all__ = [
    # lazy-load rarely-used/heavy builtins (for fast startup)
    "dataclasses",

View on GitHub (pinned to df599052da)

Solutions

  1. Run the install command from the message verbatim, e.g. `pip install fastexcel`
  2. Declare the polars extra(s) in requirements (e.g. `polars[excel]`, `polars[pandas]`) so optional deps ship with the env
  3. Verify the import resolves in the same interpreter: `python -c "import fastexcel"`

Example fix

# before
pl.read_excel("sheet.xlsx")  # ModuleNotFoundError: 'fastexcel' ... pip install fastexcel

# after
# pip install fastexcel
pl.read_excel("sheet.xlsx")
Defensive patterns

Strategy: validation

Validate before calling

import importlib.util

# e.g. before pl.read_excel / write_excel
deps = {"fastexcel": "read_excel", "xlsxwriter": "write_excel"}
missing = [m for m in deps if importlib.util.find_spec(m) is None]
if missing:
    raise RuntimeError("missing optional deps: " + " ".join(f"pip install {m}" for m in missing))

Try / catch

try:
    pl.read_excel(path)
except ModuleNotFoundError as e:
    # the message already contains the exact `pip install <pkg>` command
    log.error("dependency missing: %s", e)
    raise

Prevention

When it happens

Trigger: Using optional I/O or interop features without their dependency: reading Excel (fastexcel/xlsxwriter), database/deltalake connectors, pandas conversion helpers — each polars function declares the module it needs and routes the import through this helper.

Common situations: Base polars install without extras; code that gained a new `read_excel`/`write_excel`/database call without updating requirements; notebooks where the dependency was installed into a different kernel.

Related errors


AI-assisted analysis of pola-rs/polars@df599052da (2026-08-16). Data as JSON: /api/errors/6ef4140c66cf292b. Report an issue: GitHub.