Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ModuleNotFoundError: No module named 'langchain_community' #21880

Open
5 tasks done
KaiQiang-Liu1994 opened this issue May 19, 2024 · 9 comments
Open
5 tasks done

ModuleNotFoundError: No module named 'langchain_community' #21880

KaiQiang-Liu1994 opened this issue May 19, 2024 · 9 comments
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature

Comments

@KaiQiang-Liu1994
Copy link

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangChain documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).

Example Code

#----part0导入所需要的类
import os
import requests
from PIL import Image
from transformers import BlipProcessor, BlipForConditionalGeneration
from langchain.tools import BaseTool
from langchain import OpenAI
from langchain.agents import initialize_agent,AgentType

#----part1 初始化图像字母生成
hf_model = "Salesforce/blip-image-caption-large"
processor = BlipProcessor.from_pretrained(hf_model)
model = BlipForConditionalGeneration.from_pretrained(hf_model)

#--定义图像字母生成工具类
class ImageCapTool(BaseTool):
name = "Image captioner"
description = "为图片创作说明文案"

def _run(self,url:str):
    image = Image.open(requests.get(url,stream=True).raw).convert("RGB")
    inputs = processor(image,return_tensors="pt")
    out = model.generate(**inputs,max_new_tokens=20)
    caption = processor.decode(out[0],skip_special_tokens=True)
    return caption


def _arun(self,query:str):
    raise NotImplementedError("This tool does not support async")

os.environ["OPENAI_API_KEY"] = ""
llm = OpenAI(temperature=0.2)
tools = [ImageCapTool]
agent = initialize_agent(
agent = AgentType.ZERO_SHOT_REACT_DESCRIPTION,
tools=tools,
llm=llm,
verbose = True,
)

image_url = "https://image.baidu.com/search/detail?ct=503316480&z=undefined&tn=baiduimagedetail&ipn=d&word=%E7%8E%AB%E7%91%B0&step_word=&lid=8350970360390223282&ie=utf-8&in=&cl=2&lm=-1&st=undefined&hd=undefined&latest=undefined&copyright=undefined&cs=1485018591,1347421720&os=1568910280,55160396&simid=3419305429,75243099&pn=6&rn=1&di=7355526631391232001&ln=1941&fr=&fmq=1716115722875_R&fm=&ic=undefined&s=undefined&se=&sme=&tab=0&width=undefined&height=undefined&face=undefined&is=0,0&istype=0&ist=&jit=&bdtype=0&spn=0&pi=0&gsm=1e&objurl=https%3A%2F%2Fs2.best-wallpaper.net%2Fwallpaper%2Fiphone%2F1911%2FOne-red-rose-petals-black-background_iphone_640x1136.jpg&rpstart=0&rpnum=0&adpicid=0&nojc=undefined&dyTabStr=MCwxLDMsMiw2LDQsNSw4LDcsOQ%3D%3D"
agent.invoke(input=f'{image_url}\n请创作合适的中文推广文案')

Error Message and Stack Trace (if applicable)

D:\miniconda\envs\llm\python.exe D:\langchain_code\langchain0519\demo02.py
Traceback (most recent call last):
File "D:\langchain_code\langchain0519\demo02.py", line 7, in
from langchain import OpenAI
File "D:\miniconda\envs\llm\Lib\site-packages\langchain_init_.py", line 189, in getattr
from langchain_community.llms import OpenAI
ModuleNotFoundError: No module named 'langchain_community'

Description

D:\miniconda\envs\llm\python.exe D:\langchain_code\langchain0519\demo02.py
Traceback (most recent call last):
File "D:\langchain_code\langchain0519\demo02.py", line 7, in
from langchain import OpenAI
File "D:\miniconda\envs\llm\Lib\site-packages\langchain_init_.py", line 189, in getattr
from langchain_community.llms import OpenAI
ModuleNotFoundError: No module named 'langchain_community'

System Info

D:\miniconda\envs\llm\python.exe D:\langchain_code\langchain0519\demo02.py
Traceback (most recent call last):
File "D:\langchain_code\langchain0519\demo02.py", line 7, in
from langchain import OpenAI
File "D:\miniconda\envs\llm\Lib\site-packages\langchain_init_.py", line 189, in getattr
from langchain_community.llms import OpenAI
ModuleNotFoundError: No module named 'langchain_community'

@dosubot dosubot bot added the 🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature label May 19, 2024
@kavyabhargava
Copy link

Facing same issue

@laishzh
Copy link
Contributor

laishzh commented May 20, 2024

You can try this command to install langchain_community manually.
pip install langchain-community.

Reason: langchain-community is not automatically installed in langchain v0.2.

@kavyabhargava
Copy link

Tried that too. Still getting error: ModuleNotFoundError Traceback (most recent call last)
Cell In[4], line 1
----> 1 from langchain.chat_models import ChatOpenAI

File ~/opt/anaconda3/lib/python3.9/site-packages/langchain/chat_models/init.py:27, in getattr(name)
26 def getattr(name: str) -> None:
---> 27 from langchain_community import chat_models
29 # If not in interactive env, raise warning.
30 if not is_interactive_env():

ModuleNotFoundError: No module named 'langchain_community'

@Vitalis001
Copy link

@kavyabhargava try this command to install.
pip install langchain-community --trusted-host mirrors.cloud.tencent.com

@arc-ch
Copy link

arc-ch commented May 26, 2024

@kavyabhargava try this command to install. pip install langchain-community --trusted-host mirrors.cloud.tencent.com

facing the same issue even after doing this

@Thoams0211
Copy link

You can try this command to install langchain_community manually. pip install langchain-community.

Reason: langchain-community is not automatically installed in langchain v0.2.

It is usful

@panuoksala
Copy link

If you are using conda, you need to add conda-forge as channel into conda.
image

Then you can install langchain-community package and it should start to work.

@maurice6411
Copy link

You can try this command to install langchain_community manually. pip install langchain-community.

Reason: langchain-community is not automatically installed in langchain v0.2.

Lifesaver

@Achbi
Copy link

Achbi commented Jun 9, 2024

you can try
pip install langchain-community
and if you are using openai key than
pip install langchain_openai
and instead of from langchain import OpenAI
use from langchain_openai import OpenAI

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature
Projects
None yet
Development

No branches or pull requests

9 participants