Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'langchain' is not a package

Running into this error while trying to run a basic tutorial script for langchain:

ModuleNotFoundError: No module named 'langchain.llms'; 'langchain' is not a package

Here is the code snippet:

from langchain.llms import OpenAI
llm = OpenAI(temperature=0.9)
text = "What is a popular recipe using coconut milk?"
print(llm(text))
like image 493
Deepak Joy Cheenath Avatar asked Sep 19 '25 20:09

Deepak Joy Cheenath


1 Answers

The issue was that one of my project files was named langchain.py. Renaming the file fixed this issue, otherwise it was importing the file instead of the actual library.

Found the answer here originally: https://github.com/hwchase17/langchain/issues/2079

like image 170
Deepak Joy Cheenath Avatar answered Sep 21 '25 12:09

Deepak Joy Cheenath