langchain-ai/langchain · error · ImportError
Install Pyppeteer to use the Pyppeteer method: `pip install
Error message
Install Pyppeteer to use the Pyppeteer method: `pip install pyppeteer`.
What it means
When draw_mermaid_png() is called with MermaidDrawMethod.PYPPETEER, rendering launches a headless Chromium via pyppeteer. If pyppeteer is not installed, _render_mermaid_using_pyppeteer raises this ImportError telling you the exact extra required.
Source
Thrown at libs/core/langchain_core/runnables/graph_mermaid.py:344
f"Invalid draw method: {draw_method}. "
f"Supported draw methods are: {supported_methods}"
)
raise ValueError(msg)
return img_bytes
async def _render_mermaid_using_pyppeteer(
mermaid_syntax: str,
output_file_path: str | None = None,
background_color: str | None = "white",
padding: int = 10,
device_scale_factor: int = 3,
) -> bytes:
"""Renders Mermaid graph using Pyppeteer."""
if not _HAS_PYPPETEER:
msg = "Install Pyppeteer to use the Pyppeteer method: `pip install pyppeteer`."
raise ImportError(msg)
browser = await launch()
page = await browser.newPage()
# Setup Mermaid JS
await page.goto("about:blank")
await page.addScriptTag(
{"url": "https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js"}
)
await page.evaluate(
"""() => {
mermaid.initialize({startOnLoad:true});
}"""
)
# Render SVG
svg_code = await page.evaluate(
"""(mermaidGraph) => {View on GitHub (pinned to e32fa9a52e)
Solutions
- pip install pyppeteer, then run pyppeteer-install once to fetch Chromium
- If pyppeteer fails to install/run (common on Python 3.10+), switch to the default draw_method=MermaidDrawMethod.API
- For fully offline pipelines, render Mermaid with an external tool (e.g. mermaid-cli) instead
Example fix
# before draw_mermaid_png(syntax, draw_method=MermaidDrawMethod.PYPPETEER) # ImportError # after pip install pyppeteer && pyppeteer-install draw_mermaid_png(syntax, draw_method=MermaidDrawMethod.PYPPETEER)
Defensive patterns
Strategy: validation
Validate before calling
try:
import pyppeteer # noqa: F401
ok = True
except ImportError:
ok = False
if not ok:
draw_mermaid_png(syntax) # default API path Try / catch
try:
img = draw_mermaid_png(syntax, draw_method=MermaidDrawMethod.PYPPETEER)
except ImportError:
img = draw_mermaid_png(syntax) # fall back to API Prevention
- Prefer MermaidDrawMethod.API unless you must render offline
- Run pyppeteer-install in your Dockerfile so Chromium is present before first use
When it happens
Trigger: draw_mermaid_png(syntax, draw_method=MermaidDrawMethod.PYPPETEER) in an environment without pyppeteer.
Common situations: Opting for local rendering to avoid the mermaid.ink network API but forgetting the optional dependency; pyppeteer is also unmaintained and its bundled Chromium download often breaks on modern Python versions.
Related errors
- Install the `requests` module to use the Mermaid.INK API: `p
- Install pygraphviz to draw graphs: `pip install pygraphviz`.
- Install grandalf to draw graphs: `pip install grandalf`.
- Invalid draw method: {draw_method}. Supported draw methods a
- Found duplicate subgraph '{subgraph}' -- this likely means t
AI-assisted analysis of langchain-ai/langchain@e32fa9a52e (2026-08-14).
Data as JSON: /api/errors/2c05caabcbea42ac.
Report an issue: GitHub.