news 2026/2/6 17:39:20

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/2/7 5:09:04

KeyCastr终极指南:快速掌握macOS按键可视化技巧

KeyCastr终极指南&#xff1a;快速掌握macOS按键可视化技巧 【免费下载链接】keycastr KeyCastr, an open-source keystroke visualizer 项目地址: https://gitcode.com/gh_mirrors/ke/keycastr 在屏幕录制、技术演示或在线教学场景中&#xff0c;你是否曾苦恼观众无法看…

作者头像 李华
网站建设 2026/2/7 0:11:39

VideoSrt终极指南:15分钟从零掌握智能字幕制作全流程

VideoSrt终极指南&#xff1a;15分钟从零掌握智能字幕制作全流程 【免费下载链接】video-srt-windows 这是一个可以识别视频语音自动生成字幕SRT文件的开源 Windows-GUI 软件工具。 项目地址: https://gitcode.com/gh_mirrors/vi/video-srt-windows 你是否曾经为了给视频…

作者头像 李华
网站建设 2026/2/2 23:03:35

这行转网安,月薪翻倍+不用加班,我后悔没早转!

目录 1.前言2.开发的痛&#xff0c;谁懂&#xff1f; ① 需求变更多&#xff0c;代码改到吐② 加班没完没了&#xff0c;身体扛不住③ 技术更新太快&#xff0c;学不过来 3.转行网安所需技能 ①.代码能力&#xff0c;天然就是安全优势② 技能高度重叠&#xff0c;转型几乎零成…

作者头像 李华
网站建设 2026/2/5 17:53:52

Tabby终端工具:Windows系统下高效命令行操作解决方案

Tabby终端工具&#xff1a;Windows系统下高效命令行操作解决方案 【免费下载链接】Tabby终端工具64位安装包 Tabby是一款功能强大的终端工具&#xff0c;专为开发者设计&#xff0c;集成了多种终端仿真功能&#xff0c;提供便捷高效的命令行操作体验。此版本为Windows 64位系统…

作者头像 李华
网站建设 2026/2/2 14:43:44

Kubernetes网络性能瓶颈如何突破?Cilium路由架构选型实战

Kubernetes网络性能瓶颈如何突破&#xff1f;Cilium路由架构选型实战 【免费下载链接】cilium Cilium 是一个开源的网络和存储编排工具&#xff0c;用于容器网络、负载均衡和网络安全。 * 用于容器网络、负载均衡和网络安全、支持多种编程语言和框架、容器网络。 * 有什么特点&…

作者头像 李华