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

导入greykite Forecaster时报TypeError:python-holidays实体加载类错误

解决导入greykite Forecaster时的holidays库TypeError问题

这个错误的核心原因是holidays库的API更新:新版本holidays移除了通过EntityLoader间接继承实体类的方式,要求直接从holidays.countries或holidays.financial导入具体实体类,但holidays_ext库的UnitedStates类仍在使用旧的继承逻辑(继承OldUnitedStates,而后者依赖已废弃的EntityLoader)。以下是可行的解决办法:

  • 锁定holidays库的兼容版本
    由于holidays_ext暂未适配holidays的新版本,回退到已知兼容的旧版本即可解决问题。执行命令:

    pip install holidays==0.35
    
  • 排查并修复依赖冲突
    如果虚拟环境中有其他依赖包强制升级了holidays,先检查依赖状态:

    pip show holidays
    pip check
    

    找到冲突的包后,要么调整该包的版本,要么在requirements.txt中明确指定holidays的版本:

    holidays==0.35
    
  • 手动适配holidays新版本(进阶方案)
    若需要使用holidays的新版本,可修改holidays_ext的代码:
    找到虚拟环境中holidays_ext的安装路径,打开united_states.py文件,将原继承逻辑:

    from holidays.countries.united_states import OldUnitedStates
    class UnitedStates(OldUnitedStates):
        # 原类自定义逻辑
    

    替换为直接继承holidays官方的UnitedStates类:

    from holidays.countries import UnitedStates as BaseUS
    class UnitedStates(BaseUS):
        # 保留原类自定义逻辑
    

内容的提问来源于stack exchange,提问作者Nestor Ingles

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.15 10:24:59