diff --git a/langchain/graphs/networkx_graph.py b/langchain/graphs/networkx_graph.py index f48fe0f144..66dd5bb25a 100644 --- a/langchain/graphs/networkx_graph.py +++ b/langchain/graphs/networkx_graph.py @@ -50,7 +50,13 @@ class NetworkxEntityGraph: def __init__(self) -> None: """Create a new graph.""" - import networkx as nx + try: + import networkx as nx + except ImportError: + raise ValueError( + "Could not import networkx python package. " + "Please it install it with `pip install networkx`." + ) self._graph = nx.DiGraph()