从fbprophet包导入holidays时报错求助(版本0.7.1)
解决fbprophet 0.7.1导入holidays模块间歇性TypeError问题
问题根源
fbprophet 0.7.1对python-holidays的版本依赖范围较宽松,当环境中安装的python-holidays版本过高(≥0.20)时,其内部实体加载逻辑发生了变更,而旧版fbprophet的代码未适配该变化,从而间歇性触发导入错误。
可行解决办法
- 锁定兼容的python-holidays版本:安装与fbprophet 0.7.1匹配的
python-holidays版本,推荐锁定在0.19.0及以下。执行命令:
若使用requirements.txt管理依赖,添加一行:pip install holidays==0.19.0holidays<=0.19.0 - 替换导入逻辑:如果无法降级
python-holidays,直接绕过fbprophet的中间导入层,从python-holidays的官方路径导入所需实体,示例:from holidays.countries import China # 按需替换为你需要的国家/地区实体 # 若要兼容原有代码,可做简单映射 hdays_part2 = __import__('holidays') - 清理缓存重装依赖:缓存的旧模块可能导致间歇性异常,执行以下命令清理并重新安装:
pip cache purge pip uninstall -y fbprophet holidays pip install fbprophet==0.7.1 holidays==0.19.0
内容的提问来源于stack exchange,提问作者Sarang Manjrekar
相关产品推荐
相关产品推荐

