MacOS 10.15.5+Python3.10.10下导入Prophet模块报TypeError如何解决?
问题:MacOS 10.15.5 + Python 3.10.10下导入FBProphet报错TypeError
在MacOS 10.15.5系统、Python 3.10.10环境下,已通过pip成功安装FBProphet模块,但执行导入语句from prophet import Prophet时遇到如下TypeError错误:
TypeError Traceback (most recent call last) Cell In[4], line 2 1 #Trying the FP Prophet model on the data ----> 2 from prophet import Prophet File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/prophet/__init__.py:7 1 # Copyright (c) 2017-present, Facebook, Inc. 2 # All rights reserved. 3 # 4 # This source code is licensed under the BSD-style license found in the 5 # LICENSE file in the root directory of this source tree. An additional grant 6 # of patent rights can be found in the PATENTS file in the same directory. ----> 7 from prophet.forecaster import Prophet 9 from pathlib import Path 10 about = {} File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/prophet/forecaster.py:19 16 import pandas as pd 17 from numpy.typing import NDArray ---> 19 from prophet.make_holidays import get_holiday_names, make_holidays_df 20 from prophet.models import StanBackendEnum 21 from prophet.plot import (plot, plot_components) File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/prophet/make_holidays.py:14 ... 175 self.entity_name = entity_path[-1] 176 self.module_name = ".".join(entity_path[0:-1]) ---> 178 super().__init__(*args, **kwargs) TypeError: object.__init__() takes exactly one argument (the instance to initialize)
可能的原因及解决方法
- 依赖版本不兼容:这个报错大概率是
holidays库的版本与FBProphet不匹配导致的。FBProphet对holidays库有特定版本要求,版本过高或过低都会引发类初始化时的参数错误。- 先卸载当前的holidays库:
pip uninstall -y holidays - 安装兼容版本,例如FBProphet v1.1.5推荐搭配
holidays<=0.28:pip install holidays==0.28
- 先卸载当前的holidays库:
- Python版本适配问题:Python 3.10在MacOS 10.15.5上可能存在部分库的兼容性问题,若上述方法无效,可尝试降级Python到3.9版本,再重新安装FBProphet及对应依赖。
- 重新安装FBProphet:确保安装官方维护的最新稳定版,卸载现有版本后重新安装:
pip uninstall -y prophetpip install prophet --no-cache-dir
内容的提问来源于stack exchange,提问作者BroodjeBal
相关产品推荐
相关产品推荐

