news 2026/8/21 18:41:44

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/8/21 2:23:46

终极Mac观影神器:打造你的私人美剧影院

终极Mac观影神器&#xff1a;打造你的私人美剧影院 【免费下载链接】iMeiJu_Mac 爱美剧Mac客户端 项目地址: https://gitcode.com/gh_mirrors/im/iMeiJu_Mac 还在为找美剧资源而烦恼吗&#xff1f;在各大视频平台间频繁切换&#xff0c;只为找到心仪的那一部&#xff1f…

作者头像 李华
网站建设 2026/8/21 4:21:44

Linux下通过命令行实现防火墙操作

在Linux系统上管理防火墙&#xff0c;ufw (Uncomplicated Firewall) 是一个非常流行且易于使用的工具&#xff0c;它是 iptables 的一个前端。 &#x1f527; UFW的安装 ufw 通常预装在基于Debian的系统&#xff08;如Ubuntu&#xff09;上。如果你的系统没有&#xff0c;可以使…

作者头像 李华
网站建设 2026/8/20 16:16:59

测试数据管理的自动化工具

被忽视的质量基石 在敏捷开发与持续交付成为主流的今天&#xff0c;测试数据管理&#xff08;TDM&#xff09;仍存在明显滞后性。据行业调研显示&#xff0c;超过67%的软件缺陷源于测试数据问题——数据污染、覆盖不全、环境差异等痛点直接拖累交付周期。本文通过解构自动化工…

作者头像 李华
网站建设 2026/8/20 19:41:24

智能测试数据脱敏技术:保障数据安全与测试效率的工程实践

测试数据管理的困境与破局 在敏捷开发与DevOps普及的今天&#xff0c;软件测试活动日趋频繁。传统的测试数据准备方式——无论是直接使用生产数据的“裸奔”行为&#xff0c;还是耗费大量人力手动编写模拟数据的“作坊”模式——都已无法满足现代软件工程对效率、安全与质量的…

作者头像 李华
网站建设 2026/8/21 17:09:19

MTK设备bootrom保护绕过技术详解:专业级安全解锁方案

MTK设备bootrom保护绕过技术详解&#xff1a;专业级安全解锁方案 【免费下载链接】bypass_utility 项目地址: https://gitcode.com/gh_mirrors/by/bypass_utility MTK芯片设备的安全保护机制一直是手机刷机和系统定制的重要障碍。本工具通过技术手段实现对bootrom保护的…

作者头像 李华