Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ModuleNotFoundError: No module named 'langchain_openai'

Following LangChain docs in my Jupyter notebook with the following code :

from langchain_openai import ChatOpenAI
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser


prompt = ChatPromptTemplate.from_template("Tell me a short joke about {topic}")
model = ChatOpenAI(model="gpt-3.5-turbo")
output_parser = StrOutputParser()

chain = prompt | model | output_parser

Docs say that pip install langchain installs all necessary modules, including langchain-community and langchain-core

However, I get this error:

ModuleNotFoundError: No module named 'langchain_openai'

like image 265
Ari Avatar asked Jan 25 '26 01:01

Ari


1 Answers

In addition to Ari response, from LangChain version 0.0.10, the ChatOpenAI from the langchain-community package has been deprecated and it will be soon removed from that same package (see: Python API):

[docs]@deprecated(
    since="0.0.10", 
    removal="0.2.0", 
    alternative_import="langchain_openai.ChatOpenAI"
)
class ChatOpenAI(BaseChatModel):

The correct usage of the class can be found in the langchain-openai package, which (for some reasons...) does not come by default when installing LangChain from PyPI. The package is the following: OpenAI Integration.

You can directly install the package by running:

pip install langchain-openai

LangChain is continuously evolving so it is generally difficult to keep the pace of those changing. I suggest to always refer to the official documentation for understanding where to find classes and functions based on the specific version of LangChain installed.

like image 157
dvdr00t Avatar answered Jan 26 '26 18:01

dvdr00t



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!