docling-project/docling · error · RuntimeError

Libreoffice not found

Error message

Libreoffice not found

What it means

get_libreoffice_cmd(raise_if_unavailable=True) in docling.backend.docx.drawingml.utils raises this RuntimeError when LibreOffice cannot be located: it checks shutil.which('libreoffice'), then shutil.which('soffice'), then the standard macOS .app bundle path. If none is found it refuses to continue; when a command is found it additionally smoke-tests it with '-h' so a broken binary also fails here.

Source

Thrown at docling/backend/docx/drawingml/utils.py:42

"""


def get_libreoffice_cmd(raise_if_unavailable: bool = False) -> Optional[str]:
    """Return the libreoffice cmd and optionally test it."""

    libreoffice_cmd = (
        shutil.which("libreoffice")
        or shutil.which("soffice")
        or (
            "/Applications/LibreOffice.app/Contents/MacOS/soffice"
            if os.path.isfile("/Applications/LibreOffice.app/Contents/MacOS/soffice")
            else None
        )
    )

    if raise_if_unavailable:
        if libreoffice_cmd is None:
            raise RuntimeError("Libreoffice not found")

        # The following test will raise if the libreoffice_cmd cannot be used
        subprocess.run(
            [
                libreoffice_cmd,
                "-h",
            ],
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
            check=True,
        )

    return libreoffice_cmd


@contextmanager
def _isolated_libreoffice_profile() -> Iterator[str]:
    """Yield a ``-env:UserInstallation`` argument backed by a throwaway profile.

View on GitHub (pinned to 61d76f1ff3)

Solutions

  1. Install LibreOffice in the environment: apt-get install -y libreoffice (Debian/Ubuntu), dnf install libreoffice (Fedora), brew install --cask libreoffice (macOS).
  2. Ensure the binary is on PATH for the process that runs docling: which libreoffice || which soffice must succeed; for macOS add /Applications/LibreOffice.app/Contents/MacOS to PATH or install to the default location.
  3. In Docker, install libreoffice (or just libreoffice-impress + libreoffice-core) in the image rather than at runtime.
  4. If LibreOffice is intentionally absent, avoid the DrawingML/shape-conversion code path or make the calling feature optional.

Example fix

# before (Dockerfile)
FROM python:3.12-slim
RUN pip install docling
# convert with drawings -> RuntimeError: Libreoffice not found

# after
FROM python:3.12-slim
RUN apt-get update && apt-get install -y --no-install-recommends libreoffice && rm -rf /var/lib/apt/lists/*
RUN pip install docling
Defensive patterns

Strategy: validation

Validate before calling

import shutil, os, subprocess

def libreoffice_available() -> bool:
    cmd = (shutil.which("libreoffice") or shutil.which("soffice")
           or ("/Applications/LibreOffice.app/Contents/MacOS/soffice"
               if os.path.isfile("/Applications/LibreOffice.app/Contents/MacOS/soffice") else None))
    if cmd is None:
        return False
    return subprocess.run([cmd, "-h"], stdout=subprocess.DEVNULL,
                          stderr=subprocess.DEVNULL).returncode == 0

Try / catch

try:
    result = conv.convert(docx_path)
except RuntimeError as e:
    if "Libreoffice not found" in str(e):
        raise RuntimeError("Install LibreOffice (apt-get install -y libreoffice) and ensure soffice is on PATH") from e
    raise

Prevention

When it happens

Trigger: Any docling code path that renders DOCX DrawingML images/drawings via LibreOffice conversion on a machine where libreoffice/soffice is not on PATH and (on macOS) the app is not installed at /Applications/LibreOffice.app. Also when the found binary cannot execute (corrupt install, missing libs) — the subprocess.run(check=True) then raises instead.

Common situations: Minimal Docker images (python:slim) without LibreOffice installed; macOS where LibreOffice was installed to a non-default location; CI runners assuming docling's base dependencies include LibreOffice; PATH not propagated in service environments (systemd, cron, containers).

Related errors


AI-assisted analysis of docling-project/docling@61d76f1ff3 (2026-08-14). Data as JSON: /api/errors/3a844cb1c5f82584. Report an issue: GitHub.