langchain-ai / langgraph-studio

Desktop app for prototyping and debugging LangGraph applications locally.
https://studio.langchain.com
1.99k stars 131 forks source link

ImportError: attempted relative import with no known parent package #181

Closed majorgilles closed 3 weeks ago

majorgilles commented 3 weeks ago

I get the following error (in the graph.py file) when a try to boot up langgraph studio from a nested package.

from .components.models import AgentState

ImportError: attempted relative import with no known parent package

I'm aware this may be more of a usability issue than a bug, but I simply don't know how to solve it because I have very little control over how docker is used to package the graphs.


Project structure is the following:

Screenshot 2024-11-03 at 11 07 05

As you can see, all elements in the project hierarchy are python packages, starting from tutorials.

Unfortunately, the packaging doesn't work when running langgraph studio, although it does when importing from pure python code. When attempting to start the graph in langgraph studio, I get: ImportError: attempted relative import with no known parent package

I tried absolute imports like this:

from tutorials.topics.rag.agentic_rag.components.models import AgentState

but that doesn't work either as the docker process / container has no visibility over directories / modules above the langgraph.json (I get no module "tutorials" found error in this case.

Is there a better to achieve the result I want that would be compatible with both running from a python script and in the langgraph studio app?

majorgilles commented 3 weeks ago

In the end this was caused by the IDE setting an incorrect import path when working with multiple python packages at different levels.