{"record":{"id":"e2498abcc0b6852a","repo":"tirth8205/code-review-graph","slug":"matplotlib-is-required-for-svg-export-install-wit","errorCode":null,"errorMessage":"matplotlib is required for SVG export. Install with: pip install matplotlib","messagePattern":"matplotlib is required for SVG export\\. Install with: pip install matplotlib","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"code_review_graph/exports.py","lineNumber":368,"sourceCode":"    return slug[:100] or \"unnamed\"\n\n\n# -------------------------------------------------------------------\n# SVG export (matplotlib-based)\n# -------------------------------------------------------------------\n\ndef export_svg(store: GraphStore, output_path: Path) -> Path:\n    \"\"\"Export a static SVG graph visualization.\n\n    Requires matplotlib (optional dependency).\n    Returns the path to the written file.\n    \"\"\"\n    try:\n        import matplotlib\n        matplotlib.use(\"Agg\")\n        import matplotlib.pyplot as plt\n    except ImportError:\n        raise ImportError(\n            \"matplotlib is required for SVG export. \"\n            \"Install with: pip install matplotlib\"\n        )\n\n    import networkx as nx\n\n    data = export_graph_data(store)\n    nodes_data = data[\"nodes\"]\n    edges_data = data[\"edges\"]\n\n    nxg: nx.DiGraph = nx.DiGraph()  # type: ignore[type-arg]\n    for n in nodes_data:\n        nxg.add_node(\n            n[\"qualified_name\"],\n            label=n.get(\"name\", \"\"),\n            kind=n.get(\"kind\", \"\"),\n        )\n    for e in edges_data:","sourceCodeStart":350,"sourceCodeEnd":386,"githubUrl":"https://github.com/tirth8205/code-review-graph/blob/b58668751ab0c7670c078cf7cbd4d1f5b8e54f81/code_review_graph/exports.py#L350-L386","documentation":"export_svg() imports matplotlib lazily (with the Agg backend); if matplotlib is not installed the ImportError is re-raised with install instructions. SVG export is an optional dependency.","triggerScenarios":"Calling export_svg() (e.g. the export --svg CLI path via main) in an environment where matplotlib isn't installed.","commonSituations":"Installing the package without optional extras, slim Docker images, or assuming networkx alone suffices for visualization.","solutions":["pip install matplotlib","Or add matplotlib to your project's dependencies/requirements","Use export_dot/export_json instead if you can't install matplotlib"],"exampleFix":"# before\npip install code-review-graph\n# after\npip install code-review-graph matplotlib","handlingStrategy":"validation","validationCode":"try:\n    import matplotlib  # noqa\nexcept ImportError:\n    raise RuntimeError(\"SVG export unavailable; pip install matplotlib or use export_json\")","typeGuard":"def svg_export_available() -> bool:\n    try:\n        import matplotlib  # noqa\n        return True\n    except ImportError:\n        return False","tryCatchPattern":"try:\n    export_svg(store, \"out.svg\")\nexcept ImportError as e:\n    if \"matplotlib\" in str(e):\n        export_json(store, \"out.json\")  # fallback format\n    else:\n        raise","preventionTips":["Declare matplotlib in your deployment dependencies if you export SVG","Gate SVG export on an availability check","Offer dot/json export as a dependency-free fallback"],"tags":["matplotlib","svg-export","missing-dependency"],"backgroundTag":"missing-optional-dependency","analyzedSha":"b58668751ab0c7670c078cf7cbd4d1f5b8e54f81","analyzedAt":"2026-08-28T13:19:08.966Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}