news 2026/8/6 22:10:00

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/6 10:28:31

EdXposed框架完全指南:从入门到实战的Hook技术详解

EdXposed框架完全指南&#xff1a;从入门到实战的Hook技术详解 【免费下载链接】EdXposed Elder driver Xposed Framework. 项目地址: https://gitcode.com/gh_mirrors/edx/EdXposed EdXposed框架作为Android系统上功能强大的Hook技术解决方案&#xff0c;为开发者提供了…

作者头像 李华
网站建设 2026/8/6 5:01:25

DBeaver数据库对象搜索功能故障排查与恢复指南

DBeaver数据库对象搜索功能故障排查与恢复指南 【免费下载链接】dbeaver DBeaver 是一个通用的数据库管理工具&#xff0c;支持跨平台使用。* 支持多种数据库类型&#xff0c;如 MySQL、PostgreSQL、MongoDB 等&#xff1b;提供 SQL 编辑、查询、调试等功能&#xff1b;支持数据…

作者头像 李华
网站建设 2026/8/6 3:54:42

游戏AI自动化新纪元:GameAISDK框架实战指南

游戏AI自动化新纪元&#xff1a;GameAISDK框架实战指南 【免费下载链接】GameAISDK 基于图像的游戏AI自动化框架 项目地址: https://gitcode.com/gh_mirrors/ga/GameAISDK 在游戏开发领域&#xff0c;AI自动化测试正成为提升开发效率的关键技术。GameAISDK作为腾讯开源的…

作者头像 李华
网站建设 2026/8/6 17:46:05

48tools:一站式多工具集成平台完整使用指南

48tools&#xff1a;一站式多工具集成平台完整使用指南 【免费下载链接】48tools 48工具&#xff0c;提供公演、口袋48直播录源&#xff0c;公演、口袋48录播下载&#xff0c;封面下载&#xff0c;B站直播抓取&#xff0c;B站视频下载&#xff0c;A站直播抓取&#xff0c;A站视…

作者头像 李华