cannot import ToolNode from Langgraph #139

Closed
opened 2026-02-20 17:28:50 -05:00 by yindo · 14 comments
Owner

Originally created by @rajidhamon31 on GitHub (Jul 8, 2024).

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangGraph/LangChain documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangGraph/LangChain rather than my code.
  • I am sure this is better as an issue rather than a GitHub discussion, since this is a LangGraph bug and not a design question.

Example Code

from langchain_core.runnables import RunnableLambda, RunnableWithFallbacks
from langgraph.prebuilt import ToolNode


def create_tool_node_with_fallback(tools: list) -> RunnableWithFallbacks[Any, dict]:
    """
    Create a ToolNode with a fallback to handle errors and surface them to the agent.
    """
    return ToolNode(tools).with_fallbacks(
        [RunnableLambda(handle_tool_error)], exception_key="error"
    )

Error Message and Stack Trace (if applicable)

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
Cell In[66], line 2
      1 from langchain_core.runnables import RunnableLambda, RunnableWithFallbacks
----> 2 from langgraph.prebuilt import ToolNode
      5 def create_tool_node_with_fallback(tools: list) -> RunnableWithFallbacks[Any, dict]:
      6     """
      7     Create a ToolNode with a fallback to handle errors and surface them to the agent.
      8     """

ImportError: cannot import name 'ToolNode' from 'langgraph.prebuilt' (/home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages/langgraph/prebuilt/__init__.py)

Description

I am getting this error today, when I was able to execute it before

System Info

from langgraph.prebuilt import ToolNode

Originally created by @rajidhamon31 on GitHub (Jul 8, 2024). ### Checked other resources - [X] I added a very descriptive title to this issue. - [X] I searched the [LangGraph](https://langchain-ai.github.io/langgraph/)/LangChain documentation with the integrated search. - [X] I used the GitHub search to find a similar question and didn't find it. - [X] I am sure that this is a bug in LangGraph/LangChain rather than my code. - [X] I am sure this is better as an issue [rather than a GitHub discussion](https://github.com/langchain-ai/langgraph/discussions/new/choose), since this is a LangGraph bug and not a design question. ### Example Code ```python from langchain_core.runnables import RunnableLambda, RunnableWithFallbacks from langgraph.prebuilt import ToolNode def create_tool_node_with_fallback(tools: list) -> RunnableWithFallbacks[Any, dict]: """ Create a ToolNode with a fallback to handle errors and surface them to the agent. """ return ToolNode(tools).with_fallbacks( [RunnableLambda(handle_tool_error)], exception_key="error" ) ``` ### Error Message and Stack Trace (if applicable) ```shell --------------------------------------------------------------------------- ImportError Traceback (most recent call last) Cell In[66], line 2 1 from langchain_core.runnables import RunnableLambda, RunnableWithFallbacks ----> 2 from langgraph.prebuilt import ToolNode 5 def create_tool_node_with_fallback(tools: list) -> RunnableWithFallbacks[Any, dict]: 6 """ 7 Create a ToolNode with a fallback to handle errors and surface them to the agent. 8 """ ImportError: cannot import name 'ToolNode' from 'langgraph.prebuilt' (/home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages/langgraph/prebuilt/__init__.py) ``` ### Description I am getting this error today, when I was able to execute it before ### System Info from langgraph.prebuilt import ToolNode
yindo added the stale label 2026-02-20 17:28:50 -05:00
yindo closed this issue 2026-02-20 17:28:52 -05:00
Author
Owner

@vbarda commented on GitHub (Jul 8, 2024):

@rajidhamon31 what version of langgraph are you using?

@vbarda commented on GitHub (Jul 8, 2024): @rajidhamon31 what version of `langgraph` are you using?
Author
Owner

@hinthornw commented on GitHub (Jul 8, 2024):

+1, please fill out the system info as required by the issue template.

@hinthornw commented on GitHub (Jul 8, 2024): +1, please fill out the system info as required by the issue template.
Author
Owner

@laavanjan commented on GitHub (Feb 27, 2025):

how did u solve it, I'm getting the same error

@laavanjan commented on GitHub (Feb 27, 2025): how did u solve it, I'm getting the same error
Author
Owner

@nishantguvvada commented on GitHub (Feb 27, 2025):

@laavanjan update the langgraph version to 0.3.1 ( I was getting the same error )

@nishantguvvada commented on GitHub (Feb 27, 2025): @laavanjan update the langgraph version to 0.3.1 ( I was getting the same error )
Author
Owner

@gbaian10 commented on GitHub (Feb 28, 2025):

Do you have langgraph-prebuilt installed?
https://github.com/langchain-ai/langgraph/releases/tag/0.3.1

@gbaian10 commented on GitHub (Feb 28, 2025): Do you have `langgraph-prebuilt` installed? https://github.com/langchain-ai/langgraph/releases/tag/0.3.1
Author
Owner

@timonschramm commented on GitHub (Mar 3, 2025):

For those still struggling: Try it in a fresh environement as suggested here: https://github.com/langchain-ai/langgraph/discussions/3613

Then it worked for me!

@timonschramm commented on GitHub (Mar 3, 2025): For those still struggling: Try it in a fresh environement as suggested here: https://github.com/langchain-ai/langgraph/discussions/3613 Then it worked for me!
Author
Owner

@windowshopr commented on GitHub (Mar 6, 2025):

I'm getting this error too trying to follow along with the "Quickstart: Launch Local LangGraph Server" documentation here. Allow me to step through the process and the issues I've run into so far.

Windows 10
Python 3.11.9
langgraph==0.3.5
langchain==0.3.20
langchain-cli==0.0.35
langgraph-cli==0.1.75

On the page it says:

Image

so I run the command pip install langchain-cli[inmem]>=0.1.58, but am met with:

ERROR: Ignored the following yanked versions: 0.0.1, 0.0.2
ERROR: Could not find a version that satisfies the requirement langchain-cli>=0.1.58 (from versions: 0.0.1rc0, 0.0.1rc2, 0.0.1rc3, 0.0.1rc4, 0.0.3, 0.0.4, 0.0.5, 0.0.6, 0.0.8, 0.0.9, 0.0.10, 0.0.11, 0.0.12, 0.0.13, 0.0.14, 0.0.15, 0.0.16, 0.0.17, 0.0.18, 0.0.19, 0.0.20rc0, 0.0.20, 0.0.21, 0.0.22rc0, 0.0.22rc1, 0.0.22, 0.0.23, 0.0.24, 0.0.25, 0.0.26, 0.0.27, 0.0.28, 0.0.29, 0.0.30, 0.0.31, 0.0.32, 0.0.33, 0.0.34, 0.0.35)
ERROR: No matching distribution found for langchain-cli>=0.1.58

So I think what that spot is meant to say is pip install langgraph-cli[inmem]>=0.1.58 given the page also says:

Image

...but as a newbie reading the page from top down, the first command it shows is confusing. So got that figured out.

Next, I create an empty folder, cd into it, and run the command langgraph new . and choose options 2 (for simple react agent) and option 1 (for Python). The React app creates successfully.

I create a copy of the .env.example and rename it to .env, run pip install -e . as it says, and finally run langgraph dev, where I get this traceback:

langgraph dev
INFO:langgraph_api.cli:

        Welcome to

╦  ┌─┐┌┐┌┌─┐╔═╗┬─┐┌─┐┌─┐┬ ┬
║  ├─┤││││ ┬║ ╦├┬┘├─┤├─┘├─┤
╩═╝┴ ┴┘└┘└─┘╚═╝┴└─┴ ┴┴  ┴ ┴

- 🚀 API: ←[36mhttp://127.0.0.1:2024←[0m
- 🎨 Studio UI: ←[36mhttps://smith.langchain.com/studio/?baseUrl=http://127.0.0.1:2024←[0m
- 📚 API Docs: ←[36mhttp://127.0.0.1:2024/docs←[0m

This in-memory server is designed for development and testing.
For production use, please use LangGraph Cloud.


2025-03-06T19:27:38.084993Z [info     ] Will watch for changes in these directories: ['I:\\nasty\\Python_Projects\\LLM\\LangGraph\\langchain-academy\\module-1\\studio\\langgraph_app_matts'] [uvicorn.error] api_variant=local_dev
2025-03-06T19:27:38.086995Z [info     ] Uvicorn running on http://127.0.0.1:2024 (Press CTRL+C to quit) [uvicorn.error] api_variant=local_dev color_message=Uvicorn running on %s://%s:%d (Press CTRL+C to quit)
2025-03-06T19:27:38.087992Z [info     ] Started reloader process [31668] using WatchFiles [uvicorn.error] api_variant=local_dev color_message=Started reloader process [31668] using WatchFiles
2025-03-06T19:27:43.990685Z [info     ] Using auth of type=noop        [langgraph_api.auth.middleware] api_variant=local_dev
2025-03-06T19:27:44.006622Z [info     ] Started server process [135672] [uvicorn.error] api_variant=local_dev color_message=Started server process [%d]
2025-03-06T19:27:44.007623Z [info     ] Waiting for application startup. [uvicorn.error] api_variant=local_dev
2025-03-06T19:27:44.202872Z [info     ] 1 change detected              [watchfiles.main] api_variant=local_dev
2025-03-06T19:27:44.590554Z [error    ] Traceback (most recent call last):
  File "C:\Users\chalu\AppData\Local\Programs\Python\Python311\Lib\site-packages\starlette\routing.py", line 692, in lifespan
    async with self.lifespan_context(app) as maybe_state:
  File "C:\Users\chalu\AppData\Local\Programs\Python\Python311\Lib\contextlib.py", line 210, in __aenter__
    return await anext(self.gen)
           ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\chalu\AppData\Local\Programs\Python\Python311\Lib\site-packages\langgraph_api\lifespan.py", line 30, in lifespan
    await collect_graphs_from_env(True)
  File "C:\Users\chalu\AppData\Local\Programs\Python\Python311\Lib\site-packages\langgraph_api\graph.py", line 257, in collect_graphs_from_env
    graph = await run_in_executor(None, _graph_from_spec, spec)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\chalu\AppData\Local\Programs\Python\Python311\Lib\site-packages\langchain_core\runnables\config.py", line 588, in run_in_executor
    return await asyncio.get_running_loop().run_in_executor(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\chalu\AppData\Local\Programs\Python\Python311\Lib\concurrent\futures\thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\chalu\AppData\Local\Programs\Python\Python311\Lib\site-packages\langchain_core\runnables\config.py", line 579, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\chalu\AppData\Local\Programs\Python\Python311\Lib\site-packages\langgraph_api\graph.py", line 295, in _graph_from_spec
    modspec.loader.exec_module(module)
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "I:\nasty\Python_Projects\LLM\LangGraph\langchain-academy\module-1\studio\langgraph_app_matts\./src/react_agent/graph.py", line 12, in <module>
    from langgraph.prebuilt import ToolNode
ImportError: cannot import name 'ToolNode' from 'langgraph.prebuilt' (unknown location)
Could not import python module for graph:
GraphSpec(id='agent', path='./src/react_agent/graph.py', module=None, variable='graph', config=None)
This error likely means you haven't installed your project and its dependencies yet. Before running the server, install your project:

If you are using requirements.txt:
python -m pip install -r requirements.txt

If you are using pyproject.toml or setuptools:
python -m pip install -e .

Make sure to run this command from your project's root directory (where your setup.py or pyproject.toml is located)

So it appears to be something with langgraph.prebuilt either not being installed properly (or at all), perhaps a version issue (although I think I'm running the latest version of langgraph), or something else. Very frustrating as a newbie trying to follow along the documentation.

What do I do? This is clearly a "new environment" with fresh installs. I tried with langgraph version 0.3.2 as well, same issue.

@windowshopr commented on GitHub (Mar 6, 2025): I'm getting this error too trying to follow along with the "Quickstart: Launch Local LangGraph Server" documentation [here](https://langchain-ai.github.io/langgraph/tutorials/langgraph-platform/local-server/). Allow me to step through the process and the issues I've run into so far. Windows 10 Python 3.11.9 langgraph==0.3.5 langchain==0.3.20 langchain-cli==0.0.35 langgraph-cli==0.1.75 On the page it says: ![Image](https://github.com/user-attachments/assets/43a23161-c2fd-4596-9179-0b807b3f768e) so I run the command `pip install langchain-cli[inmem]>=0.1.58`, but am met with: ``` ERROR: Ignored the following yanked versions: 0.0.1, 0.0.2 ERROR: Could not find a version that satisfies the requirement langchain-cli>=0.1.58 (from versions: 0.0.1rc0, 0.0.1rc2, 0.0.1rc3, 0.0.1rc4, 0.0.3, 0.0.4, 0.0.5, 0.0.6, 0.0.8, 0.0.9, 0.0.10, 0.0.11, 0.0.12, 0.0.13, 0.0.14, 0.0.15, 0.0.16, 0.0.17, 0.0.18, 0.0.19, 0.0.20rc0, 0.0.20, 0.0.21, 0.0.22rc0, 0.0.22rc1, 0.0.22, 0.0.23, 0.0.24, 0.0.25, 0.0.26, 0.0.27, 0.0.28, 0.0.29, 0.0.30, 0.0.31, 0.0.32, 0.0.33, 0.0.34, 0.0.35) ERROR: No matching distribution found for langchain-cli>=0.1.58 ``` So I think what that spot is meant to say is `pip install langgraph-cli[inmem]>=0.1.58` given the page also says: ![Image](https://github.com/user-attachments/assets/7cc88827-bc58-4856-ab83-173e892dce7e) ...but as a newbie reading the page from top down, the first command it shows is confusing. So got that figured out. Next, I create an empty folder, cd into it, and run the command `langgraph new .` and choose options 2 (for simple react agent) and option 1 (for Python). The React app creates successfully. I create a copy of the `.env.example` and rename it to `.env`, run `pip install -e .` as it says, and finally run `langgraph dev`, where I get this traceback: ``` langgraph dev INFO:langgraph_api.cli: Welcome to ╦ ┌─┐┌┐┌┌─┐╔═╗┬─┐┌─┐┌─┐┬ ┬ ║ ├─┤││││ ┬║ ╦├┬┘├─┤├─┘├─┤ ╩═╝┴ ┴┘└┘└─┘╚═╝┴└─┴ ┴┴ ┴ ┴ - 🚀 API: ←[36mhttp://127.0.0.1:2024←[0m - 🎨 Studio UI: ←[36mhttps://smith.langchain.com/studio/?baseUrl=http://127.0.0.1:2024←[0m - 📚 API Docs: ←[36mhttp://127.0.0.1:2024/docs←[0m This in-memory server is designed for development and testing. For production use, please use LangGraph Cloud. 2025-03-06T19:27:38.084993Z [info ] Will watch for changes in these directories: ['I:\\nasty\\Python_Projects\\LLM\\LangGraph\\langchain-academy\\module-1\\studio\\langgraph_app_matts'] [uvicorn.error] api_variant=local_dev 2025-03-06T19:27:38.086995Z [info ] Uvicorn running on http://127.0.0.1:2024 (Press CTRL+C to quit) [uvicorn.error] api_variant=local_dev color_message=Uvicorn running on %s://%s:%d (Press CTRL+C to quit) 2025-03-06T19:27:38.087992Z [info ] Started reloader process [31668] using WatchFiles [uvicorn.error] api_variant=local_dev color_message=Started reloader process [31668] using WatchFiles 2025-03-06T19:27:43.990685Z [info ] Using auth of type=noop [langgraph_api.auth.middleware] api_variant=local_dev 2025-03-06T19:27:44.006622Z [info ] Started server process [135672] [uvicorn.error] api_variant=local_dev color_message=Started server process [%d] 2025-03-06T19:27:44.007623Z [info ] Waiting for application startup. [uvicorn.error] api_variant=local_dev 2025-03-06T19:27:44.202872Z [info ] 1 change detected [watchfiles.main] api_variant=local_dev 2025-03-06T19:27:44.590554Z [error ] Traceback (most recent call last): File "C:\Users\chalu\AppData\Local\Programs\Python\Python311\Lib\site-packages\starlette\routing.py", line 692, in lifespan async with self.lifespan_context(app) as maybe_state: File "C:\Users\chalu\AppData\Local\Programs\Python\Python311\Lib\contextlib.py", line 210, in __aenter__ return await anext(self.gen) ^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\chalu\AppData\Local\Programs\Python\Python311\Lib\site-packages\langgraph_api\lifespan.py", line 30, in lifespan await collect_graphs_from_env(True) File "C:\Users\chalu\AppData\Local\Programs\Python\Python311\Lib\site-packages\langgraph_api\graph.py", line 257, in collect_graphs_from_env graph = await run_in_executor(None, _graph_from_spec, spec) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\chalu\AppData\Local\Programs\Python\Python311\Lib\site-packages\langchain_core\runnables\config.py", line 588, in run_in_executor return await asyncio.get_running_loop().run_in_executor( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\chalu\AppData\Local\Programs\Python\Python311\Lib\concurrent\futures\thread.py", line 58, in run result = self.fn(*self.args, **self.kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\chalu\AppData\Local\Programs\Python\Python311\Lib\site-packages\langchain_core\runnables\config.py", line 579, in wrapper return func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\chalu\AppData\Local\Programs\Python\Python311\Lib\site-packages\langgraph_api\graph.py", line 295, in _graph_from_spec modspec.loader.exec_module(module) File "<frozen importlib._bootstrap_external>", line 940, in exec_module File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed File "I:\nasty\Python_Projects\LLM\LangGraph\langchain-academy\module-1\studio\langgraph_app_matts\./src/react_agent/graph.py", line 12, in <module> from langgraph.prebuilt import ToolNode ImportError: cannot import name 'ToolNode' from 'langgraph.prebuilt' (unknown location) Could not import python module for graph: GraphSpec(id='agent', path='./src/react_agent/graph.py', module=None, variable='graph', config=None) This error likely means you haven't installed your project and its dependencies yet. Before running the server, install your project: If you are using requirements.txt: python -m pip install -r requirements.txt If you are using pyproject.toml or setuptools: python -m pip install -e . Make sure to run this command from your project's root directory (where your setup.py or pyproject.toml is located) ``` So it appears to be something with langgraph.prebuilt either not being installed properly (or at all), perhaps a version issue (although I think I'm running the latest version of langgraph), or something else. Very frustrating as a newbie trying to follow along the documentation. What do I do? This is clearly a "new environment" with fresh installs. I tried with langgraph version 0.3.2 as well, same issue.
Author
Owner

@rick98033 commented on GitHub (Mar 15, 2025):

it works on version 0.2.74 ...

@rick98033 commented on GitHub (Mar 15, 2025): it works on version 0.2.74 ...
Author
Owner

@hinthornw commented on GitHub (Apr 2, 2025):

Things to check if you run into this:

  1. You have langgraph-prebuilt installed in your environment.
  2. If this is only happening when running the CLI, please confirm that the cli is using the langgraph-api version installed in your local virtual environment rather than something installed globally.
@hinthornw commented on GitHub (Apr 2, 2025): Things to check if you run into this: 1. You have `langgraph-prebuilt` installed in your environment. 2. If this is only happening when running the CLI, please confirm that the cli is using the `langgraph-api` version installed in your local virtual environment rather than something installed globally.
Author
Owner

@Eskiii commented on GitHub (Apr 28, 2025):

I'm getting this error too trying to follow along with the "Quickstart: Launch Local LangGraph Server" documentation here. Allow me to step through the process and the issues I've run into so far.

Windows 10 Python 3.11.9 langgraph==0.3.5 langchain==0.3.20 langchain-cli==0.0.35 langgraph-cli==0.1.75

On the page it says:

Image

so I run the command pip install langchain-cli[inmem]>=0.1.58, but am met with:

ERROR: Ignored the following yanked versions: 0.0.1, 0.0.2
ERROR: Could not find a version that satisfies the requirement langchain-cli>=0.1.58 (from versions: 0.0.1rc0, 0.0.1rc2, 0.0.1rc3, 0.0.1rc4, 0.0.3, 0.0.4, 0.0.5, 0.0.6, 0.0.8, 0.0.9, 0.0.10, 0.0.11, 0.0.12, 0.0.13, 0.0.14, 0.0.15, 0.0.16, 0.0.17, 0.0.18, 0.0.19, 0.0.20rc0, 0.0.20, 0.0.21, 0.0.22rc0, 0.0.22rc1, 0.0.22, 0.0.23, 0.0.24, 0.0.25, 0.0.26, 0.0.27, 0.0.28, 0.0.29, 0.0.30, 0.0.31, 0.0.32, 0.0.33, 0.0.34, 0.0.35)
ERROR: No matching distribution found for langchain-cli>=0.1.58

So I think what that spot is meant to say is pip install langgraph-cli[inmem]>=0.1.58 given the page also says:

Image

...but as a newbie reading the page from top down, the first command it shows is confusing. So got that figured out.

Next, I create an empty folder, cd into it, and run the command langgraph new . and choose options 2 (for simple react agent) and option 1 (for Python). The React app creates successfully.

I create a copy of the .env.example and rename it to .env, run pip install -e . as it says, and finally run langgraph dev, where I get this traceback:

langgraph dev
INFO:langgraph_api.cli:

        Welcome to

╦  ┌─┐┌┐┌┌─┐╔═╗┬─┐┌─┐┌─┐┬ ┬
║  ├─┤││││ ┬║ ╦├┬┘├─┤├─┘├─┤
╩═╝┴ ┴┘└┘└─┘╚═╝┴└─┴ ┴┴  ┴ ┴

- 🚀 API: ←[36mhttp://127.0.0.1:2024←[0m
- 🎨 Studio UI: ←[36mhttps://smith.langchain.com/studio/?baseUrl=http://127.0.0.1:2024←[0m
- 📚 API Docs: ←[36mhttp://127.0.0.1:2024/docs←[0m

This in-memory server is designed for development and testing.
For production use, please use LangGraph Cloud.


2025-03-06T19:27:38.084993Z [info     ] Will watch for changes in these directories: ['I:\\nasty\\Python_Projects\\LLM\\LangGraph\\langchain-academy\\module-1\\studio\\langgraph_app_matts'] [uvicorn.error] api_variant=local_dev
2025-03-06T19:27:38.086995Z [info     ] Uvicorn running on http://127.0.0.1:2024 (Press CTRL+C to quit) [uvicorn.error] api_variant=local_dev color_message=Uvicorn running on %s://%s:%d (Press CTRL+C to quit)
2025-03-06T19:27:38.087992Z [info     ] Started reloader process [31668] using WatchFiles [uvicorn.error] api_variant=local_dev color_message=Started reloader process [31668] using WatchFiles
2025-03-06T19:27:43.990685Z [info     ] Using auth of type=noop        [langgraph_api.auth.middleware] api_variant=local_dev
2025-03-06T19:27:44.006622Z [info     ] Started server process [135672] [uvicorn.error] api_variant=local_dev color_message=Started server process [%d]
2025-03-06T19:27:44.007623Z [info     ] Waiting for application startup. [uvicorn.error] api_variant=local_dev
2025-03-06T19:27:44.202872Z [info     ] 1 change detected              [watchfiles.main] api_variant=local_dev
2025-03-06T19:27:44.590554Z [error    ] Traceback (most recent call last):
  File "C:\Users\chalu\AppData\Local\Programs\Python\Python311\Lib\site-packages\starlette\routing.py", line 692, in lifespan
    async with self.lifespan_context(app) as maybe_state:
  File "C:\Users\chalu\AppData\Local\Programs\Python\Python311\Lib\contextlib.py", line 210, in __aenter__
    return await anext(self.gen)
           ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\chalu\AppData\Local\Programs\Python\Python311\Lib\site-packages\langgraph_api\lifespan.py", line 30, in lifespan
    await collect_graphs_from_env(True)
  File "C:\Users\chalu\AppData\Local\Programs\Python\Python311\Lib\site-packages\langgraph_api\graph.py", line 257, in collect_graphs_from_env
    graph = await run_in_executor(None, _graph_from_spec, spec)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\chalu\AppData\Local\Programs\Python\Python311\Lib\site-packages\langchain_core\runnables\config.py", line 588, in run_in_executor
    return await asyncio.get_running_loop().run_in_executor(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\chalu\AppData\Local\Programs\Python\Python311\Lib\concurrent\futures\thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\chalu\AppData\Local\Programs\Python\Python311\Lib\site-packages\langchain_core\runnables\config.py", line 579, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\chalu\AppData\Local\Programs\Python\Python311\Lib\site-packages\langgraph_api\graph.py", line 295, in _graph_from_spec
    modspec.loader.exec_module(module)
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "I:\nasty\Python_Projects\LLM\LangGraph\langchain-academy\module-1\studio\langgraph_app_matts\./src/react_agent/graph.py", line 12, in <module>
    from langgraph.prebuilt import ToolNode
ImportError: cannot import name 'ToolNode' from 'langgraph.prebuilt' (unknown location)
Could not import python module for graph:
GraphSpec(id='agent', path='./src/react_agent/graph.py', module=None, variable='graph', config=None)
This error likely means you haven't installed your project and its dependencies yet. Before running the server, install your project:

If you are using requirements.txt:
python -m pip install -r requirements.txt

If you are using pyproject.toml or setuptools:
python -m pip install -e .

Make sure to run this command from your project's root directory (where your setup.py or pyproject.toml is located)

So it appears to be something with langgraph.prebuilt either not being installed properly (or at all), perhaps a version issue (although I think I'm running the latest version of langgraph), or something else. Very frustrating as a newbie trying to follow along the documentation.

What do I do? This is clearly a "new environment" with fresh installs. I tried with langgraph version 0.3.2 as well, same issue.

I also encountered the same problem when using langgraph server...Have you solved the problem?

@Eskiii commented on GitHub (Apr 28, 2025): > I'm getting this error too trying to follow along with the "Quickstart: Launch Local LangGraph Server" documentation [here](https://langchain-ai.github.io/langgraph/tutorials/langgraph-platform/local-server/). Allow me to step through the process and the issues I've run into so far. > > Windows 10 Python 3.11.9 langgraph==0.3.5 langchain==0.3.20 langchain-cli==0.0.35 langgraph-cli==0.1.75 > > On the page it says: > > ![Image](https://github.com/user-attachments/assets/43a23161-c2fd-4596-9179-0b807b3f768e) > > so I run the command `pip install langchain-cli[inmem]>=0.1.58`, but am met with: > > ``` > ERROR: Ignored the following yanked versions: 0.0.1, 0.0.2 > ERROR: Could not find a version that satisfies the requirement langchain-cli>=0.1.58 (from versions: 0.0.1rc0, 0.0.1rc2, 0.0.1rc3, 0.0.1rc4, 0.0.3, 0.0.4, 0.0.5, 0.0.6, 0.0.8, 0.0.9, 0.0.10, 0.0.11, 0.0.12, 0.0.13, 0.0.14, 0.0.15, 0.0.16, 0.0.17, 0.0.18, 0.0.19, 0.0.20rc0, 0.0.20, 0.0.21, 0.0.22rc0, 0.0.22rc1, 0.0.22, 0.0.23, 0.0.24, 0.0.25, 0.0.26, 0.0.27, 0.0.28, 0.0.29, 0.0.30, 0.0.31, 0.0.32, 0.0.33, 0.0.34, 0.0.35) > ERROR: No matching distribution found for langchain-cli>=0.1.58 > ``` > > So I think what that spot is meant to say is `pip install langgraph-cli[inmem]>=0.1.58` given the page also says: > > ![Image](https://github.com/user-attachments/assets/7cc88827-bc58-4856-ab83-173e892dce7e) > > ...but as a newbie reading the page from top down, the first command it shows is confusing. So got that figured out. > > Next, I create an empty folder, cd into it, and run the command `langgraph new .` and choose options 2 (for simple react agent) and option 1 (for Python). The React app creates successfully. > > I create a copy of the `.env.example` and rename it to `.env`, run `pip install -e .` as it says, and finally run `langgraph dev`, where I get this traceback: > > ``` > langgraph dev > INFO:langgraph_api.cli: > > Welcome to > > ╦ ┌─┐┌┐┌┌─┐╔═╗┬─┐┌─┐┌─┐┬ ┬ > ║ ├─┤││││ ┬║ ╦├┬┘├─┤├─┘├─┤ > ╩═╝┴ ┴┘└┘└─┘╚═╝┴└─┴ ┴┴ ┴ ┴ > > - 🚀 API: ←[36mhttp://127.0.0.1:2024←[0m > - 🎨 Studio UI: ←[36mhttps://smith.langchain.com/studio/?baseUrl=http://127.0.0.1:2024←[0m > - 📚 API Docs: ←[36mhttp://127.0.0.1:2024/docs←[0m > > This in-memory server is designed for development and testing. > For production use, please use LangGraph Cloud. > > > 2025-03-06T19:27:38.084993Z [info ] Will watch for changes in these directories: ['I:\\nasty\\Python_Projects\\LLM\\LangGraph\\langchain-academy\\module-1\\studio\\langgraph_app_matts'] [uvicorn.error] api_variant=local_dev > 2025-03-06T19:27:38.086995Z [info ] Uvicorn running on http://127.0.0.1:2024 (Press CTRL+C to quit) [uvicorn.error] api_variant=local_dev color_message=Uvicorn running on %s://%s:%d (Press CTRL+C to quit) > 2025-03-06T19:27:38.087992Z [info ] Started reloader process [31668] using WatchFiles [uvicorn.error] api_variant=local_dev color_message=Started reloader process [31668] using WatchFiles > 2025-03-06T19:27:43.990685Z [info ] Using auth of type=noop [langgraph_api.auth.middleware] api_variant=local_dev > 2025-03-06T19:27:44.006622Z [info ] Started server process [135672] [uvicorn.error] api_variant=local_dev color_message=Started server process [%d] > 2025-03-06T19:27:44.007623Z [info ] Waiting for application startup. [uvicorn.error] api_variant=local_dev > 2025-03-06T19:27:44.202872Z [info ] 1 change detected [watchfiles.main] api_variant=local_dev > 2025-03-06T19:27:44.590554Z [error ] Traceback (most recent call last): > File "C:\Users\chalu\AppData\Local\Programs\Python\Python311\Lib\site-packages\starlette\routing.py", line 692, in lifespan > async with self.lifespan_context(app) as maybe_state: > File "C:\Users\chalu\AppData\Local\Programs\Python\Python311\Lib\contextlib.py", line 210, in __aenter__ > return await anext(self.gen) > ^^^^^^^^^^^^^^^^^^^^^ > File "C:\Users\chalu\AppData\Local\Programs\Python\Python311\Lib\site-packages\langgraph_api\lifespan.py", line 30, in lifespan > await collect_graphs_from_env(True) > File "C:\Users\chalu\AppData\Local\Programs\Python\Python311\Lib\site-packages\langgraph_api\graph.py", line 257, in collect_graphs_from_env > graph = await run_in_executor(None, _graph_from_spec, spec) > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > File "C:\Users\chalu\AppData\Local\Programs\Python\Python311\Lib\site-packages\langchain_core\runnables\config.py", line 588, in run_in_executor > return await asyncio.get_running_loop().run_in_executor( > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > File "C:\Users\chalu\AppData\Local\Programs\Python\Python311\Lib\concurrent\futures\thread.py", line 58, in run > result = self.fn(*self.args, **self.kwargs) > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > File "C:\Users\chalu\AppData\Local\Programs\Python\Python311\Lib\site-packages\langchain_core\runnables\config.py", line 579, in wrapper > return func(*args, **kwargs) > ^^^^^^^^^^^^^^^^^^^^^ > File "C:\Users\chalu\AppData\Local\Programs\Python\Python311\Lib\site-packages\langgraph_api\graph.py", line 295, in _graph_from_spec > modspec.loader.exec_module(module) > File "<frozen importlib._bootstrap_external>", line 940, in exec_module > File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed > File "I:\nasty\Python_Projects\LLM\LangGraph\langchain-academy\module-1\studio\langgraph_app_matts\./src/react_agent/graph.py", line 12, in <module> > from langgraph.prebuilt import ToolNode > ImportError: cannot import name 'ToolNode' from 'langgraph.prebuilt' (unknown location) > Could not import python module for graph: > GraphSpec(id='agent', path='./src/react_agent/graph.py', module=None, variable='graph', config=None) > This error likely means you haven't installed your project and its dependencies yet. Before running the server, install your project: > > If you are using requirements.txt: > python -m pip install -r requirements.txt > > If you are using pyproject.toml or setuptools: > python -m pip install -e . > > Make sure to run this command from your project's root directory (where your setup.py or pyproject.toml is located) > ``` > > So it appears to be something with langgraph.prebuilt either not being installed properly (or at all), perhaps a version issue (although I think I'm running the latest version of langgraph), or something else. Very frustrating as a newbie trying to follow along the documentation. > > What do I do? This is clearly a "new environment" with fresh installs. I tried with langgraph version 0.3.2 as well, same issue. I also encountered the same problem when using langgraph server...Have you solved the problem?
Author
Owner

@Midnight-719 commented on GitHub (May 4, 2025):

I uninstalled langgraph-cli[inmem] and langgraph-prebuilt from my environment using:

  uv pip uninstall langgraph-cli[inmem]
  uv pip uninstall langgraph-prebuilt

After removing these packages, I reinstalled them in my local virtual environment:

   uv add  langgraph-cli[inmem]
   uv add  langgraph-prebuilt

Everything works as expected now.

@Midnight-719 commented on GitHub (May 4, 2025): I uninstalled `langgraph-cli[inmem]` and `langgraph-prebuilt` from my environment using: ```shell uv pip uninstall langgraph-cli[inmem] uv pip uninstall langgraph-prebuilt ``` After removing these packages, I reinstalled them in my local virtual environment: ```shell uv add langgraph-cli[inmem] uv add langgraph-prebuilt ``` Everything works as expected now.
Author
Owner

@Xiaoye119 commented on GitHub (May 12, 2025):

from langgraph.prebuilt.tool_node import ToolNode

tools = [fetch_real_time_info]
tool_node = ToolNode(tools)

in this version is work :
langchain 0.3.25
langchain-cli 0.0.36
langchain-core 0.3.59
langchain-openai 0.3.16
langchain-text-splitters 0.3.8
langgraph 0.4.3
langgraph-checkpoint 2.0.25
langgraph-prebuilt 0.1.8
langgraph-sdk 0.1.66
langserve 0.3.1
langsmith 0.3.42

@Xiaoye119 commented on GitHub (May 12, 2025): from langgraph.prebuilt.tool_node import ToolNode tools = [fetch_real_time_info] tool_node = ToolNode(tools) in this version is work : langchain 0.3.25 langchain-cli 0.0.36 langchain-core 0.3.59 langchain-openai 0.3.16 langchain-text-splitters 0.3.8 langgraph 0.4.3 langgraph-checkpoint 2.0.25 langgraph-prebuilt 0.1.8 langgraph-sdk 0.1.66 langserve 0.3.1 langsmith 0.3.42
Author
Owner

@gdbhattacharya commented on GitHub (Jul 8, 2025):

Checked other resources

  • I added a very descriptive title to this issue.[x] I searched the LangGraph/LangChain documentation with the integrated search.[x] I used the GitHub search to find a similar question and didn't find it.[x] I am sure that this is a bug in LangGraph/LangChain rather than my code.[x] I am sure this is better as an issue rather than a GitHub discussion, since this is a LangGraph bug and not a design question.

Example Code

from langchain_core.runnables import RunnableLambda, RunnableWithFallbacks
from langgraph.prebuilt import ToolNode

def create_tool_node_with_fallback(tools: list) -> RunnableWithFallbacks[Any, dict]:
"""
Create a ToolNode with a fallback to handle errors and surface them to the agent.
"""
return ToolNode(tools).with_fallbacks(
[RunnableLambda(handle_tool_error)], exception_key="error"
)

Error Message and Stack Trace (if applicable)


ImportError Traceback (most recent call last)
Cell In[66], line 2
1 from langchain_core.runnables import RunnableLambda, RunnableWithFallbacks
----> 2 from langgraph.prebuilt import ToolNode
5 def create_tool_node_with_fallback(tools: list) -> RunnableWithFallbacks[Any, dict]:
6 """
7 Create a ToolNode with a fallback to handle errors and surface them to the agent.
8 """

ImportError: cannot import name 'ToolNode' from 'langgraph.prebuilt' (/home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages/langgraph/prebuilt/__init__.py)

Description

I am getting this error today, when I was able to execute it before

System Info

from langgraph.prebuilt import ToolNode

Yes, even I'm facing this issue after I ungraded langgraph. Most likely it has been moved to some other library.

@gdbhattacharya commented on GitHub (Jul 8, 2025): > ### Checked other resources > * [x] I added a very descriptive title to this issue.[x] I searched the [LangGraph](https://langchain-ai.github.io/langgraph/)/LangChain documentation with the integrated search.[x] I used the GitHub search to find a similar question and didn't find it.[x] I am sure that this is a bug in LangGraph/LangChain rather than my code.[x] I am sure this is better as an issue [rather than a GitHub discussion](https://github.com/langchain-ai/langgraph/discussions/new/choose), since this is a LangGraph bug and not a design question. > > ### Example Code > from langchain_core.runnables import RunnableLambda, RunnableWithFallbacks > from langgraph.prebuilt import ToolNode > > > def create_tool_node_with_fallback(tools: list) -> RunnableWithFallbacks[Any, dict]: > """ > Create a ToolNode with a fallback to handle errors and surface them to the agent. > """ > return ToolNode(tools).with_fallbacks( > [RunnableLambda(handle_tool_error)], exception_key="error" > ) > ### Error Message and Stack Trace (if applicable) > --------------------------------------------------------------------------- > ImportError Traceback (most recent call last) > Cell In[66], line 2 > 1 from langchain_core.runnables import RunnableLambda, RunnableWithFallbacks > ----> 2 from langgraph.prebuilt import ToolNode > 5 def create_tool_node_with_fallback(tools: list) -> RunnableWithFallbacks[Any, dict]: > 6 """ > 7 Create a ToolNode with a fallback to handle errors and surface them to the agent. > 8 """ > > ImportError: cannot import name 'ToolNode' from 'langgraph.prebuilt' (/home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages/langgraph/prebuilt/__init__.py) > ### Description > I am getting this error today, when I was able to execute it before > > ### System Info > from langgraph.prebuilt import ToolNode Yes, even I'm facing this issue after I ungraded langgraph. Most likely it has been moved to some other library.
Author
Owner

@sahil0094 commented on GitHub (Aug 6, 2025):

Issue resolved post installing langgraph==0.6.3

@sahil0094 commented on GitHub (Aug 6, 2025): Issue resolved post installing langgraph==0.6.3
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraph#139