RecursiveCharacterTextSplitter is missing after a LangChain upgrade
ImportError: cannot import name 'RecursiveCharacterTextSplitter' from 'langchain'Short answer
Text splitters have their own package, langchain-text-splitters. The class is imported with from langchain_text_splitters import RecursiveCharacterTextSplitter, not from the langchain package. Install the package into the Python that runs your code, change the import, and use split_text for strings or create_documents for Document objects.
Fix it fast
1Find out which cause you have
Ask pip whether the splitters package is installed in the interpreter that fails.
python -m pip show langchain-text-splitters2Match what you see, then jump to its fix
What does the error look like?
ImportError: cannot import name 'RecursiveCharacterTextSplitter' from 'langchain'ModuleNotFoundError: No module named 'langchain_text_splitters'
Cause 1 of 2
The import still uses the old langchain path
1Check
Search for the old module name.
grep -rn "text_splitter" --include=*.py .2Fix
Import from the dedicated module.
from langchain_text_splitters import RecursiveCharacterTextSplitter
splitter = RecursiveCharacterTextSplitter(chunk_size=500, chunk_overlap=50)
chunks = splitter.split_text(text)3Verify
The import and a split run without an error.
python -c "from langchain_text_splitters import RecursiveCharacterTextSplitter; print('ok')"Confirmed by docs.langchain.com
Cause 2 of 2
langchain-text-splitters is not installed in this environment
1Check
pip show prints nothing for the package. In a notebook or an IDE, the Python may differ from your terminal's.
python -c "import sys; print(sys.executable)"
python -m pip list | grep -i langchain2Fix
Install with that same Python, then restart the kernel or the IDE run configuration.
python -m pip install -U langchain-text-splitters3Verify
pip show prints a version and the import works.
python -m pip show langchain-text-splittersConfirmed by pypi.org
How do I stop it coming back?
- List langchain-text-splitters in requirements.txt next to langchain; do not assume one pulls the other.
- Use python -m pip so installs go to the interpreter you run.
- Check a tutorial's import lines against the current docs before copying them.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- stegnor.comMy company site: 804 pages from a Python and Jinja generator, with 15 free browser tools.
- MenuloA restaurant discovery platform in Germany, kept current by a Python ingestion pipeline.
- ShopGoAn e-commerce aggregator with a Python scraping engine behind its catalog, past 10K Google Play downloads.
Related fixes
AI
Azure OpenAI says the API deployment for this resource does not exist
The API deployment for this resource does not exist
Azure OpenAI does not take a model name in the model field.
2 causes, each with a fixAI
Azure OpenAI fails with an SSL certificate verification error
httpx.ConnectError: [SSL: CERTIFICATE_VERIFY_FAILED]
The client checks the endpoint's certificate against its CA bundle, which is certifi by default.
2 causes, each with a fixAI
LangChain says it could not import the chromadb package
ImportError: Could not import chromadb python package. Please install it with `pip install chromadb`.
The message comes from LangChain's old Chroma class, which cannot import chromadb in the Python that runs your code.
2 causes, each with a fixAI
Gemini API returns 429 RESOURCE_EXHAUSTED on the free tier
429 RESOURCE_EXHAUSTED
Gemini limits are applied per Google Cloud project, not per API key, so a new key in the same project does not reset anything.
3 causes, each with a fixAI
ChatPromptTemplate is missing the variable agent_scratchpad
Expected: ['agent_scratchpad', 'input']
A tool-calling agent keeps its tool calls and tool results in a prompt slot named agent_scratchpad.
2 causes, each with a fixAI
LangChain no longer exports AgentExecutor from langchain.agents
ImportError: cannot import name 'AgentExecutor' from 'langchain.agents'
LangChain v1 moved legacy classes into a separate package called langchain-classic, and AgentExecutor lives there now.
2 causes, each with a fix