news 2026/7/29 5:49:25

Python LangChain 开发问题:ImportError: Unable to import langchain_anthropic.

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
Python LangChain 开发问题:ImportError: Unable to import langchain_anthropic.
fromlangchain.agentsimportcreate_agentdefget_weather(city:str)->str:"""获取指定城市的天气"""returnf"{city}天气总是晴朗!"agent=create_agent(model="anthropic:claude-sonnet-4-5",tools=[get_weather],system_prompt="你是一个乐于助人的助手",)# 执行代理agent.invoke({"messages":[{"role":"user","content":"旧金山天气如何?"}]})
  • 在 Python 开发中,使用 LangChain 时,执行上述代码时,出现如下错误信息
D:\PythonCode\LangChainTest\.venv\Scripts\python.exe D:\PythonCode\LangChainTest\main.py D:\PythonCode\LangChainTest\.venv\Lib\site-packages\langchain_core\_api\deprecation.py:26: UserWarning: Core Pydantic V1 functionality isn't compatible with Python 3.14 or greater. from pydantic.v1.fields import FieldInfo as FieldInfoV1 Traceback (most recent call last): File "D:\PythonCode\LangChainTest\main.py", line 7, in <module> agent = create_agent( model="anthropic:claude-sonnet-4-5", tools=[get_weather], system_prompt="你是一个乐于助人的助手", ) File "D:\PythonCode\LangChainTest\.venv\Lib\site-packages\langchain\agents\factory.py", line 686, in create_agent model = init_chat_model(model) File "D:\PythonCode\LangChainTest\.venv\Lib\site-packages\langchain\chat_models\base.py", line 316, in init_chat_model return _init_chat_model_helper( cast("str", model), model_provider=model_provider, **kwargs, ) File "D:\PythonCode\LangChainTest\.venv\Lib\site-packages\langchain\chat_models\base.py", line 345, in _init_chat_model_helper _check_pkg("langchain_anthropic") ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^ File "D:\PythonCode\LangChainTest\.venv\Lib\site-packages\langchain\chat_models\base.py", line 533, in _check_pkg raise ImportError(msg) ImportError: Unable to import langchain_anthropic. Please install with `pip install -U langchain-anthropic` Process finished with exit code 1
问题原因
  • 这个错误信息表示 LangChain 需要相应的模型包来调用 Anthropic 模型
处理策略
  • 安装必要的模型包
pipinstalllangchain-anthropic
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/7/26 23:07:54

Obsidian图像工具包:终极图片管理与编辑指南

Obsidian图像工具包&#xff1a;终极图片管理与编辑指南 【免费下载链接】obsidian-image-toolkit An Obsidian plugin for viewing an image. 项目地址: https://gitcode.com/gh_mirrors/ob/obsidian-image-toolkit Obsidian图像工具包是专为Obsidian笔记用户设计的强大…

作者头像 李华
网站建设 2026/7/28 17:05:32

自主高性价比、高精度车规级姿态感知、倾角感知模组-应用消费级无人机、自动驾驶、机器人、智能制造、基础设施、智能穿戴等

自主高性价比、高精度车规级姿态感知、倾角感知模组-应用消费级无人机、自动驾驶、机器人、智能制造、基础设施、智能穿戴等在小说阅读器中沉浸阅读IMU 惯性测量单元(Inertial Measurement Unit) 是测量物体三轴角速度和加速度的设备。一个IMU内可能会装有三轴陀螺仪和三轴加速…

作者头像 李华
网站建设 2026/7/28 6:52:23

ComfyUI智能修复技术:图像处理的革命性突破

ComfyUI智能修复技术&#xff1a;图像处理的革命性突破 【免费下载链接】ComfyUI-Inpaint-CropAndStitch ComfyUI nodes to crop before sampling and stitch back after sampling that speed up inpainting 项目地址: https://gitcode.com/gh_mirrors/co/ComfyUI-Inpaint-Cr…

作者头像 李华
网站建设 2026/7/27 22:04:12

碳硅协同:人工智能作为碳基生命合作伙伴的终极形态分析

碳硅协同&#xff1a;人工智能作为碳基生命合作伙伴的终极形态分析您的手绘草图与“碳硅协同”的理念相结合&#xff0c;完美地阐释了未来人工智能作为碳基生命&#xff08;人类&#xff09;合作伙伴的终极形态。这远非替代关系&#xff0c;而是一种共生式进化。以下是具体分析…

作者头像 李华