Graphify-Labs/graphify · error · ImportError
neo4j driver not installed. Run: pip install neo4j
Error message
neo4j driver not installed. Run: pip install neo4j
What it means
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.
Source
Thrown at graphify/exporters/graphdb.py:26
def push_to_neo4j(
G: nx.Graph,
uri: str,
user: str,
password: str,
communities: dict[int, list[str]] | None = None,
) -> dict[str, int]:
"""Push graph directly to a running Neo4j instance via the Python driver.
Requires: pip install neo4j
Uses MERGE so re-running is safe - nodes and edges are upserted, not duplicated.
Returns a dict with counts of nodes and edges pushed.
"""
try:
from neo4j import GraphDatabase
except ImportError as e:
raise ImportError(
"neo4j driver not installed. Run: pip install neo4j"
) from e
node_community = _node_community_map(communities) if communities else {}
def _safe_rel(relation: str) -> str:
return re.sub(r"[^A-Z0-9_]", "_", relation.upper().replace(" ", "_").replace("-", "_")) or "RELATED_TO"
def _safe_label(label: str) -> str:
"""Sanitize a Neo4j node label to prevent Cypher injection."""
sanitized = re.sub(r"[^A-Za-z0-9_]", "", label)
return sanitized if sanitized else "Entity"
driver = GraphDatabase.driver(uri, auth=(user, password))
nodes_pushed = 0
edges_pushed = 0
with driver.session() as session:View on GitHub (pinned to 7fe58b0b0f)
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
Example fix
# before from graphify.exporters.graphdb import push_to_neo4j push_to_neo4j(G, uri="bolt://localhost:7687") # ImportError # after pip install neo4j push_to_neo4j(G, uri="bolt://localhost:7687")
Defensive patterns
Strategy: validation
Validate before calling
import importlib.util
if importlib.util.find_spec("neo4j") is None:
raise SystemExit("Install the neo4j driver first: pip install neo4j")
from graphify.exporters.graphdb import push_to_neo4j
push_to_neo4j(G, uri="bolt://localhost:7687") Try / catch
try:
push_to_neo4j(G, uri=uri)
except ImportError as e:
if "neo4j" in str(e):
log.warning("neo4j export skipped: %s", e)
else:
raise Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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).
Related errors
- falkordb SDK not installed. Run: pip install falkordb
- matplotlib not installed. Run: pip install matplotlib
- tree-sitter is not installed. Run: pip install 'tree-sitter>
- the '{pkg}' package is required for this backend but is not
- the 'anthropic' package is required for this backend but is
AI-assisted analysis of Graphify-Labs/graphify@7fe58b0b0f (2026-08-14).
Data as JSON: /api/errors/f60a6be8cfe4792e.
Report an issue: GitHub.