langchain: 'langchain' is not a package

Trying to run a simple script:

from langchain.llms import OpenAI
llm = OpenAI(temperature=0.9)
text = "What would be a good company name for a company that makes colorful socks?"
print(llm(text))

I’m running into this error: ModuleNotFoundError: No module named 'langchain.llms'; 'langchain' is not a package

I’ve got a virtualenv installed with langchains downloaded.

Name: langchain
Version: 0.0.39
Summary: Building applications with LLMs through composability
Home-page: https://www.github.com/hwchase17/langchain
Author:
Author-email:
License: MIT
Location: /Users/jkaye/dev/langchain-tutorial/venv/lib/python3.11/site-packages
Requires: numpy, pydantic, PyYAML, requests, SQLAlchemy
⇒  python --version
Python 3.11.0

I’m using zsh so I ran pip install 'langchain[all]'

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 28 (1 by maintainers)

Most upvoted comments

Is one of the files in your project named langchain.py by any chance? If so that’s what it’ll be actually importing, rename it and check again

image

That did it, thank you!

Is one of the files in your project named langchain.py by any chance? If so that’s what it’ll be actually importing, rename it and check again

you saved my life!

This should be highlighted, I’m one of them named file as langchain.py. Thank you!

Is one of the files in your project named langchain.py by any chance? If so that’s what it’ll be actually importing, rename it and check again

How stupid am I

that is pretty old version of langchain. The current version is 0.0.123 ,try to install it python 3.9. The same code is working for me

ahaha, seems not just me name file as langchain.py lol

I think the reason is I have a langchain.py exist in my folder,solved