Reputation: 15453
I used the following import statetement:
from langchain.llms import OpenAI
And I am getting the following error:
pycode python main.py Traceback (most recent call last): File "main.py", line 1, in from langchain.llms import openai ImportError: No module named langchain.llms
I am using Python 3.11.6 and I installed the packages using
pip3 install openai langchain
Upvotes: 0
Views: 3754
Reputation: 1
Install langchain_community
by using this command in the terminal:
pip install -U langchain-community
After this, import it as:
from langchain_community.llms import OpenAI
This worked for me.
Upvotes: 0
Reputation: 729
Issue experienced in VSCode, is probably a conflict based on having more than virtualenv from different interpreters. I went for Global interpreter, since probably having more than 1 does not help much (Python 3.12.7 (in my local machine this was the Global interpreter), Python 3.12.2 etc) in VSCode.
Choose based on your preference. I chose the intepreter I use in my repl. Run the below to see what version it is you have.
$py
Output:
Python 3.12.7 (tags/v3.12.7:0b05ead, Oct 1 2024, 03:06:41) [MSC v.1941 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information.
Then what solved my issue was deleting my python venv:
$deactivate
$rm -r venv
create a new one, and if possible (meaning it is not necessary), have a prefix-venv name based on your project to avoid confusion.
$python -m venv mySecondProjectVenV
Upvotes: 0
Reputation: 49619
it works with
Version: 0.0.274
the latest langchain
version is 0.0.320 and try to import like this:
from langchain.llms.openai import OpenAI
Maybe your python version installed an early verison of langchain due to dependency requirements
Upvotes: 0