ImportError: cannot import name 'BaseModel' from 'pydantic'

When a run in my computer PC the corresponding script of the Course “LangChain for LLM Application Development” in the code line “from langchain.chat_models import ChatOpenAI” the following error arise: "ImportError: cannot import name ‘BaseModel’ from ‘pydantic’, and can’t continue.

Can anybody help me ?. Many thanks

Hi @arsenioagb

Welcome to the community.

Don’t forget that you have to install all the packages by your own if you are running locally.

Thank you,

I know what you mean, and I’ve unstilladed and installed again the pydantic pakage and, unfortunately, the problem goes on.

What can I do?

As I said in the message of my topic, If I can’t resolve this problem, I can’t continue practicing in my local computer, the corresponding course.

Thanks, again.

Hi @arsenioagb

What Python version are you using?
Maybe could be a error regards conflict versions of python and langchain

you can try to update your langchain package by:

pip install --upgrade langchain

Hello again,

Python version: 3.7.3 and Conda version 4.7.10

I’ve upgraded the langchain package, and problem goes on.

Thank you for your attention.


I found some reports regards this error.

here some instructions to try to workaround this issue

Install the langchain using: pip install 'langchain[all]'
Then try to upgrade langchains by: pip install -U langchain

The langchaing ticket was o pen on the langchain repository and some instructions suggests that the python version must be 3.8.1 or higher.

I believe that the more reliable approach is to create a separate conda envirioment if you do not want to update your python version.

Don’t forget to upgrade you python version before to install and update you langchain package

Give it a try and let me know the results


1 Like


Following the instructions:

  • create a separate conda envirioment (python version 3.8.1)

  • pip install python-dotenv

    pip install openai

    pip install ‘langchain[all]’

I got the result with some error, which details I attach to this email.

Taking into account this result, can I continue with the next process (upgrade langchains by: pip install -U langchain)?.

Many thanks,

Result_Installation_LangChain_ Process.pdf (242 KB)

Yes. Proceed with the langchain update and try to run your code again

Okay, thank you!

It works !!!

Best regards,

1 Like

That is a good news!

I’m glad to help.

Don’t forgot to mark as a solution. It will move my answer to the top of this discussion and could help another learners with may face the same issue.

I marked solution. I hope I’ve done ok.
Thanks again

1 Like