news 2026/4/3 3:04:52

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/4/1 11:57:39

Simditor:轻量级所见即所得编辑器的完整指南

Simditor&#xff1a;轻量级所见即所得编辑器的完整指南 【免费下载链接】simditor An Easy and Fast WYSIWYG Editor 项目地址: https://gitcode.com/gh_mirrors/si/simditor Simditor是一款专为现代Web应用设计的轻量级所见即所得编辑器&#xff0c;以其简洁的界面设计…

作者头像 李华
网站建设 2026/4/2 4:33:34

如何快速在ThinkPad X230上安装macOS:终极Hackintosh指南

ThinkPad X230作为一款经典的商务笔记本电脑&#xff0c;凭借其出色的性能和稳定的硬件配置&#xff0c;成为Hackintosh爱好者的热门选择。本教程将带你一步步完成在X230上安装macOS的全过程&#xff0c;无需复杂的技术知识即可轻松上手。 【免费下载链接】X230-Hackintosh REA…

作者头像 李华
网站建设 2026/4/1 7:45:20

HYPE分布式水文模型建模方法与案例分析实践技术应用

HYPE(Hydrological Predictions for the Environment, HYPE)是由瑞典皇家水文气象局&#xff08;SMHI&#xff09;在HBV和HBV-NP模型基础上开发的新一代分布式水文模型&#xff0c;已经在全球众多地区得到广泛应用。该模型功能强大且简单易用&#xff0c; 能满足在无测量数据时…

作者头像 李华
网站建设 2026/4/3 2:43:08

摆脱局域网!Logseq 搭配cpolar公网访问让笔记管理更自由

前言&#xff1a;Logseq 的核心功能是帮助用户构建结构化知识库&#xff0c;通过双向链接将零散笔记关联起来&#xff0c;支持本地文件夹存储和多格式导出&#xff0c;无论是写日记、列计划还是整理专业资料&#xff0c;都能快速找到内容间的联系。 作为每天都用的笔记工具&…

作者头像 李华
网站建设 2026/4/1 3:10:39

3步快速配置Obsidian极致美化方案:从新手到专家的完全指南

3步快速配置Obsidian极致美化方案&#xff1a;从新手到专家的完全指南 【免费下载链接】awesome-obsidian &#x1f576;️ Awesome stuff for Obsidian 项目地址: https://gitcode.com/gh_mirrors/aw/awesome-obsidian 想要打造一个既美观又高效的Obsidian笔记环境吗&a…

作者头像 李华