{"record":{"id":"f60a6be8cfe4792e","repo":"Graphify-Labs/graphify","slug":"neo4j-driver-not-installed-run-pip-install-neo4j","errorCode":null,"errorMessage":"neo4j driver not installed. Run: pip install neo4j","messagePattern":"neo4j driver not installed\\. Run: pip install neo4j","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"graphify/exporters/graphdb.py","lineNumber":26,"sourceCode":"\ndef push_to_neo4j(\n    G: nx.Graph,\n    uri: str,\n    user: str,\n    password: str,\n    communities: dict[int, list[str]] | None = None,\n) -> dict[str, int]:\n    \"\"\"Push graph directly to a running Neo4j instance via the Python driver.\n\n    Requires: pip install neo4j\n\n    Uses MERGE so re-running is safe - nodes and edges are upserted, not duplicated.\n    Returns a dict with counts of nodes and edges pushed.\n    \"\"\"\n    try:\n        from neo4j import GraphDatabase\n    except ImportError as e:\n        raise ImportError(\n            \"neo4j driver not installed. Run: pip install neo4j\"\n        ) from e\n\n    node_community = _node_community_map(communities) if communities else {}\n\n    def _safe_rel(relation: str) -> str:\n        return re.sub(r\"[^A-Z0-9_]\", \"_\", relation.upper().replace(\" \", \"_\").replace(\"-\", \"_\")) or \"RELATED_TO\"\n\n    def _safe_label(label: str) -> str:\n        \"\"\"Sanitize a Neo4j node label to prevent Cypher injection.\"\"\"\n        sanitized = re.sub(r\"[^A-Za-z0-9_]\", \"\", label)\n        return sanitized if sanitized else \"Entity\"\n\n    driver = GraphDatabase.driver(uri, auth=(user, password))\n    nodes_pushed = 0\n    edges_pushed = 0\n\n    with driver.session() as session:","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/Graphify-Labs/graphify/blob/7fe58b0b0f3873be9a21c30106b8b8527c353aa6/graphify/exporters/graphdb.py#L8-L44","documentation":"Raised by graphify's Neo4j exporter when the `neo4j` Python package cannot be imported. The exporter is optional infrastructure tooling: it pushes the built graph to a running Neo4j instance via the Bolt driver using MERGE upserts, so the driver is imported lazily inside the function and a missing install is reported with a pip hint.","triggerScenarios":"Calling the push-to-Neo4j export function (graphdb exporter entry point, e.g. `graphify export --neo4j ...`) in an environment where `from neo4j import GraphDatabase` raises ImportError.","commonSituations":"Using the graphdb exporter from the base pip install without the graphdb extra; running in a locked-down CI image; a typo'd manual install (`pip install neo4j-driver`, which is the legacy package name).","solutions":["pip install neo4j","If you installed the legacy package, uninstall it first: `pip uninstall neo4j-driver && pip install neo4j`","Verify with `python -c \"from neo4j import GraphDatabase\"` in the same interpreter/venv that runs graphify","Confirm a Neo4j server is reachable afterwards; the driver install only fixes the import, connection errors come next"],"exampleFix":"# before\nfrom graphify.exporters.graphdb import push_to_neo4j\npush_to_neo4j(G, uri=\"bolt://localhost:7687\")  # ImportError\n\n# after\npip install neo4j\npush_to_neo4j(G, uri=\"bolt://localhost:7687\")","handlingStrategy":"validation","validationCode":"import importlib.util\n\nif importlib.util.find_spec(\"neo4j\") is None:\n    raise SystemExit(\"Install the neo4j driver first: pip install neo4j\")\n\nfrom graphify.exporters.graphdb import push_to_neo4j\npush_to_neo4j(G, uri=\"bolt://localhost:7687\")","typeGuard":null,"tryCatchPattern":"try:\n    push_to_neo4j(G, uri=uri)\nexcept ImportError as e:\n    if \"neo4j\" in str(e):\n        log.warning(\"neo4j export skipped: %s\", e)\n    else:\n        raise","preventionTips":["Install the graphdb extras in the same environment that runs the exporter","Verify `from neo4j import GraphDatabase` in a preflight check before batch export jobs","Keep the legacy `neo4j-driver` package out of the venv to avoid shadowing"],"tags":["dependency","neo4j","graph-database","import-error"],"backgroundTag":null,"analyzedSha":"7fe58b0b0f3873be9a21c30106b8b8527c353aa6","analyzedAt":"2026-08-14T19:23:21.323Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}