Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error importing langchain modules: No module named 'langchain.chains' [duplicate]

I am trying to code a FastAPI RAG application with Google Cloud and Vertex AI with python3.12 using the LangChain library.

However, when I try to import the LangChain library into my project, I keep receiving the same error repeatedly:

from langchain.chains import create_retrieval_chain

ModuleNotFoundError: No module named 'langchain.chains'

Here is my import code:

from langchain.chains import create_retrieval_chain

Here are the LangChain libraries I have installed:

langchain==1.0.5  
langchain-community==0.4.1  
langchain-text-splitters==1.0.0  
langchain-google-vertexai==3.0.3  

I installed the requirements in a virtual enviroment using uv and also tried using Python venv.

like image 780
Mateus Lira Avatar asked Dec 16 '25 11:12

Mateus Lira


1 Answers

langchain==1.0.5

langchain v1.0 was released recently (October 22, 2025), and according to the release notes, .chains and .retrievers have been moved to the langchain-classic package:

# Chains
from langchain_classic.chains import ...

# Retrievers
from langchain_classic.retrievers import ...

You're getting a ModuleNotFoundError because those imports do not exist in the langchain package in v1.0. That's why I asked for your version numbers in Staging Ground.

Some usage can be migrated to the new API; for RAG, you can look at the current RAG docs. The specific migration path depends on exactly what you were trying to do, which may be the subject of a separate question.

You can also temporarily downgrade back to v0.3 to use the older API, but it is in "maintenance" mode and will only continue to receive limited support ("security patches and critical bug fixes") until December 2026.

like image 104
agilgur5 Avatar answered Dec 18 '25 23:12

agilgur5