RecursiveCharacterTextSplitter of Langchain doesn't exist

3.8k Views Asked by At

I am trying to do a text chunking by LangChain's RecursiveCharacterTextSplitter model. I have install langchain(pip install langchain[all]), but the program still report there is no RecursiveCharacterTextSplitter package. I use from langchain.text_splitter import RecursiveCharacterTextSplitter I tried to find something on the python file of langchain and get nothing helpful. Anyone meet the same problem? Thank you for your time!

If anyone knows how to solve it, that will be great.

2

There are 2 best solutions below

3
ZKS On

Could you try below steps.

Create a virtual environment using the command

    python -m venv my_venv_name

Activate the virtual environment by executing source

    my_venv_name/bin/activate

PIP install libraries

   pip install langchain==0.0.208 
   pip install """Other required libraries like OpenAI etc..

You should now successfully able to import

    from langchain.text_splitter import RecursiveCharacterTextSplitter

Also, you can check

your langchain environment path, something as /langchain_env/lib/python3.9/site-packages/langchain/text_splitter.py, here you you should see the definition of RecursiveCharacterTextSplitter

1
j3ffyang On

In my env, I have

pip list | grep langchain
langchain                    0.0.262

then the following should work

from langchain.text_splitter import RecursiveCharacterTextSplitter