Python – How to Fix ImportError: cannot import name ‘pre_init’ from ‘langchain_core.utils’

langchainlarge-language-modelnlppippython

When I want to install langchain libraries from requirements.txt I'm getting

ImportError: cannot import name 'pre_init' from 'langchain_core.utils'

I've tried to install libraries from terminal using these commands :

pip install gigachain
pip install gigachat
pip install -U langchain-community

and it's working, so I used

pip freeze

And pasted all libraries from the terminal to requirements.txt and it's doesn't work. It would be nice if someone could help

Best Answer

Your import error suggests that the langchain-core module has not been installed. You can confirm whether this is the case by checking the output from the following command:

pip show langchain-core

If it hasn't been installed, ensure it is installed via the following command:

pip install langchain-core

As for using a requirements.txt file, simply creating it doesn't automatically install the packages listed within. You still have to run the following command in your terminal to install the listed packages:

python -m pip install -r /path/to/requirements.txt

Finally, you don't have to manually create the requirements.txt file by coping and pasting the output from pip freeze. You can simply run:

python -m pip freeze > /path/to/requirements.txt

You can read more about requirement files under the requirements files section of the pip user guide.