You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用llama_index导入pydantic v2+时触发AttributeError: module 'pydantic_core' has no attribute 'tuple_schema'

解决Pydantic v2+环境下导入SimpleDirectoryReader的tuple_schema属性错误

问题场景

在*Pydantic v2+*环境中执行以下代码:

from llama_index.core import SimpleDirectoryReader

触发错误:

AttributeError: module 'pydantic_core' has no attribute 'tuple_schema'

系统配置:

SysConfig:{'platform': 'Darwin','platform-release': '22.6.0','platform-version': 'Darwin Kernel Version 22.6.0: Wed Jul  5 22:22:52 PDT 2023; root:xnu-8796.141.3~6/RELEASE_ARM64_T8103','architecture': 'arm64','hostname': 'Air-di-W----.----.box','ip-address': '1-2.168.---.91','mac-address': '--:9d:--:cd:db:1c','processor': 'arm','ram': '8 GB'}

解决方案

  • 升级llama-index到适配Pydantic v2的版本:
    pip install --upgrade llama-index-core llama-index
    
  • 修复依赖版本不匹配问题:
    如果升级后仍报错,强制重装匹配版本的Pydantic依赖:
    pip install --force-reinstall pydantic pydantic-core
    
  • 清理缓存后重装(终极方案):
    若缓存导致依赖异常,执行以下命令:
    pip cache purge
    pip install --upgrade --no-cache-dir llama-index-core pydantic pydantic-core
    

错误原因

tuple_schema是Pydantic v1中的专属API,Pydantic v2已移除该属性。旧版本llama-index的代码仍在调用这个废弃API,因此出现兼容性错误。升级llama-index到支持Pydantic v2的版本即可解决。

内容的提问来源于stack exchange,提问作者Sandeep Kumar Kushwaha

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 16:38:09