news 2025/12/22 18:30:13

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进行投诉反馈,一经查实,立即删除!
网站建设 2025/12/12 17:38:01

PDFMathTranslate深度体验:用国产大模型实现学术论文精准翻译

PDFMathTranslate深度体验&#xff1a;用国产大模型实现学术论文精准翻译 【免费下载链接】PDFMathTranslate PDF scientific paper translation with preserved formats - 基于 AI 完整保留排版的 PDF 文档全文双语翻译&#xff0c;支持 Google/DeepL/Ollama/OpenAI 等服务&am…

作者头像 李华
网站建设 2025/12/12 17:37:50

AI工程宝典:产品运营的智能升级指南

AI工程宝典&#xff1a;产品运营的智能升级指南 【免费下载链接】aie-book [WIP] Resources for AI engineers. Also contains supporting materials for the book AI Engineering (Chip Huyen, 2025) 项目地址: https://gitcode.com/GitHub_Trending/ai/aie-book 还在为…

作者头像 李华
网站建设 2025/12/12 17:37:46

GeoJSON.io 终极指南:快速创建和编辑地理数据的免费在线工具

GeoJSON.io 终极指南&#xff1a;快速创建和编辑地理数据的免费在线工具 【免费下载链接】geojson.io A quick, simple tool for creating, viewing, and sharing spatial data 项目地址: https://gitcode.com/gh_mirrors/ge/geojson.io GeoJSON.io 是一款功能强大的免费…

作者头像 李华
网站建设 2025/12/12 17:34:55

0基础,想学习网络安全,看这一篇就够了

前言 肯定有很多人都听说过网络安全工程师这个职业&#xff0c;虽然比不上现在的前后端那么大红大紫&#xff0c;但也是一个不可小觑的技术职业&#xff0c;但你是否知道&#xff0c;网络安全工程师只是一个大的类&#xff0c;根据所作的工作内容不同可分为多个分支&#xff0…

作者头像 李华
网站建设 2025/12/12 17:34:49

Go项目配置管理终极指南:环境变量与配置文件的完美融合

Go项目配置管理终极指南&#xff1a;环境变量与配置文件的完美融合 【免费下载链接】go-clean-template Clean Architecture template for Golang services 项目地址: https://gitcode.com/gh_mirrors/go/go-clean-template 在Go项目开发中&#xff0c;你是否曾为不同环…

作者头像 李华
网站建设 2025/12/17 18:34:08

属于程序员的副业,从 0 到月入 2000,我靠挖“洞”致富!

【网络安全就业方向】网络安全专业的学生毕业后可以从事什么样的工作&#xff1f; 前言 2025年的今天&#xff0c;慎重进入网安行业吧&#xff0c;目前来说信息安全方向的就业对于学历的容忍度比软件开发要大得多&#xff0c;还有很多高中被挖过来的大佬。 理由很简单&#…

作者头像 李华