pola-rs/polars · error · ImportError

the graphviz `dot` binary should be on your PATH.(If not…

Error message

the graphviz `dot` binary should be on your PATH.(If not installed you can download here: https://graphviz.org/download/)

What it means

Polars raises this ImportError when displaying a query/dependency graph because the external Graphviz `dot` executable cannot be found. Building the DOT source is done in Python, but rendering requires the native graphviz binary installed on the system and discoverable via PATH. Polars deliberately raises with a download link rather than failing silently.

Solutions

  1. Install the Graphviz system package: `apt-get install graphviz`, `brew install graphviz`, or `winget install graphviz` / download from https://graphviz.org/download/
  2. Verify the binary is reachable: `dot -V` should print a version; if not, add its directory to PATH
  3. If you only need the DOT source, pass `output_path` and inspect the .dot file without rendering

Example fix

// before (fails: graphviz not installed)
lf.show_graph()
// after (shell)
# apt-get install graphviz
lf.show_graph()
Defensive patterns

Strategy: fallback

Validate before calling

import shutil
if shutil.which("dot") is None:
    raise SystemExit("graphviz 'dot' binary not found; install graphviz first")

Type guard

def can_render_graph() -> bool:
    return shutil.which("dot") is not None

Try / catch

try:
    lf.show_graph()
except ImportError as e:
    if "dot" in str(e):
        logging.warning("graphviz missing, skipping graph render: %s", e)
    else:
        raise

Prevention

When it happens

Trigger: Calling `lf.show_graph()` or `display_dot_graph(...)` (e.g. from LazyFrame.show_graph) when `shutil.which("dot")` fails or the graphviz Python binding cannot spawn the binary — typically because graphviz is not installed or not on PATH.

Common situations: Fresh CI containers or Docker images with Python polars pip-installed but the graphviz system package missing; venvs where graphviz was installed to a non-PATH location; Windows machines without graphviz in the system PATH.

Understand the failure class

Background: "not installed", "pip install", "required for": how missing-dependency errors surface across open-source libraries — this error's family across 34 libraries.

Related errors


AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18). Data as JSON: /api/errors/60b938adb0f03c35. Report an issue: GitHub.

Appendix: source

Thrown at py-polars/src/polars/_utils/various.py:652

    output_type = (
        "svg"
        if (output_path is not None and str(output_path).endswith(".svg"))
        or _in_notebook()
        or _in_marimo_notebook()
        or "POLARS_DOT_SVG_VIEWER" in os.environ
        else "png"
    )

    try:
        graph = subprocess.check_output(
            ["dot", "-Nshape=box", "-T" + output_type], input=f"{dot}".encode()
        )
    except (ImportError, FileNotFoundError):
        msg = (
            "the graphviz `dot` binary should be on your PATH."
            "(If not installed you can download here: https://graphviz.org/download/)"
        )
        raise ImportError(msg) from None

    if output_path:
        Path(output_path).write_bytes(graph)

    if not show:
        return None

    if _in_notebook():
        from IPython.display import SVG, display

        return display(SVG(graph))
    elif _in_marimo_notebook():
        import marimo as mo

        return mo.Html(f"{graph.decode()}")
    else:
        if (cmd := os.environ.get("POLARS_DOT_SVG_VIEWER", None)) is not None:
            import tempfile

View on GitHub (pinned to fe841f959e)