{"record":{"id":"a9b0e50728e96f90","repo":"Graphify-Labs/graphify","slug":"matplotlib-not-installed-run-pip-install-matplot","errorCode":null,"errorMessage":"matplotlib not installed. Run: pip install matplotlib","messagePattern":"matplotlib not installed\\. Run: pip install matplotlib","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"graphify/export.py","lineNumber":1102,"sourceCode":"    communities: dict[int, list[str]],\n    output_path: str,\n    community_labels: dict[int, str] | None = None,\n    figsize: tuple[int, int] = (20, 14),\n) -> None:\n    \"\"\"Export graph as an SVG file using matplotlib + spring layout.\n\n    Lightweight and embeddable - works in Obsidian notes, Notion, GitHub READMEs,\n    and any markdown renderer. No JavaScript required.\n\n    Node size scales with degree. Community colors match the HTML output.\n    \"\"\"\n    try:\n        import matplotlib\n        matplotlib.use(\"Agg\")\n        import matplotlib.pyplot as plt\n        import matplotlib.patches as mpatches\n    except ImportError as e:\n        raise ImportError(\"matplotlib not installed. Run: pip install matplotlib\") from e\n\n    node_community = _node_community_map(communities)\n\n    fig, ax = plt.subplots(figsize=figsize, facecolor=\"#1a1a2e\")\n    ax.set_facecolor(\"#1a1a2e\")\n    ax.axis(\"off\")\n\n    pos = nx.spring_layout(G, seed=42, k=2.0 / (G.number_of_nodes() ** 0.5 + 1))\n\n    degree = dict(G.degree())\n    max_deg = max(degree.values(), default=1) or 1\n\n    node_colors = [COMMUNITY_COLORS[node_community.get(n, 0) % len(COMMUNITY_COLORS)] for n in G.nodes()]\n    node_sizes = [300 + 1200 * (degree.get(n, 1) / max_deg) for n in G.nodes()]\n\n    # Draw edges - dashed for non-EXTRACTED\n    for u, v, data in G.edges(data=True):\n        conf = data.get(\"confidence\", \"EXTRACTED\")","sourceCodeStart":1084,"sourceCodeEnd":1120,"githubUrl":"https://github.com/Graphify-Labs/graphify/blob/7fe58b0b0f3873be9a21c30106b8b8527c353aa6/graphify/export.py#L1084-L1120","documentation":"Raised by graphify's Markdown graph exporter when matplotlib is not importable. matplotlib is an optional dependency used only for the static PNG/SVG community layout (spring_layout on a dark figure), so graphify guards the import and converts the underlying ImportError into an actionable message rather than failing at module load.","triggerScenarios":"Calling the markdown-embedding export function (to_markdown_graph / export with matplotlib output) in an environment where `import matplotlib` (or matplotlib.pyplot) raises ImportError — e.g. the base graphify install without the viz extra, or a venv where matplotlib was never installed.","commonSituations":"Installing graphify via `pip install graphify` (core extras only) and then requesting the matplotlib-based markdown graph; running in a slim container/CI image; a broken matplotlib install (missing system libs like libpng) also surfaces as ImportError here.","solutions":["pip install matplotlib","Or reinstall graphify with the visualization extra if one is documented (e.g. `pip install graphify[viz]`)","If the install reports success but the error persists, verify in the same interpreter: `python -c \"import matplotlib\"` and check for missing system libraries","If you don't need the static image, use the HTML or DOT exporters instead, which have no matplotlib dependency"],"exampleFix":"# before\ngraphify export --markdown graph.png   # ImportError: matplotlib not installed\n\n# after\npip install matplotlib\ngraphify export --markdown graph.png","handlingStrategy":"validation","validationCode":"import importlib.util\n\nmatplotlib_ok = importlib.util.find_spec(\"matplotlib\") is not None\nif not matplotlib_ok:\n    print(\"matplotlib missing - skipping markdown image export\")\nelse:\n    export_markdown_graph(G, communities, \"graph.png\")","typeGuard":null,"tryCatchPattern":"try:\n    export_markdown_graph(G, communities, \"graph.png\")\nexcept ImportError as e:\n    if \"matplotlib\" in str(e):\n        print(f\"skipping image export: {e}\")\n    else:\n        raise","preventionTips":["Declare matplotlib in your project's dependencies if you use image export","Probe optional deps at startup with importlib.util.find_spec and disable affected features","Pin the viz extra in the same lockfile as graphify so CI and local match"],"tags":["dependency","matplotlib","visualization","import-error"],"backgroundTag":null,"analyzedSha":"7fe58b0b0f3873be9a21c30106b8b8527c353aa6","analyzedAt":"2026-08-14T19:23:21.323Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}