facebook / prophet

Tool for producing high quality forecasts for time series data that has multiple seasonality with linear or non-linear growth.
https://facebook.github.io/prophet
MIT License
18.33k stars 4.52k forks source link

Cannot import prophet #2432

Open apisani1 opened 1 year ago

apisani1 commented 1 year ago

Hi:

I have a miniconda environment where I installed prophet. When I try to run this command on a Jupiter Notebook cell

from prophet import Prophet

I get the following error message:


__**TypeError Traceback (most recent call last) Cell In[2], line 1 ----> 1 from prophet import Prophet

File ~/miniconda3/envs/tensorflow/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 ~/miniconda3/envs/tensorflow/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 ~/miniconda3/envs/tensorflow/lib/python3.10/site-packages/prophet/make_holidays.py:14 11 import numpy as np 12 import pandas as pd ---> 14 import prophet.hdays as hdays_part2 15 import holidays as hdays_part1 18 def get_holiday_names(country):

File ~/miniconda3/envs/tensorflow/lib/python3.10/site-packages/prophet/hdays.py:779 771 pass 774 # ------------ Holidays in Turkey--------------------- 775 # This is now in Holidays, but with alias TR instead of the TU that we used. 776 # Include TU as an alias for backwards compatibility. --> 779 class TU(Turkey): 780 pass 783 # ------------ Holidays in Pakistan---------------------

File ~/miniconda3/envs/tensorflow/lib/python3.10/site-packages/holidays/registry.py:178, in EntityLoader.init(self, path, *args, *kwargs) 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)**


When I try to reinstall or upgrade prophet with pip, the system says that all the requirements are met.

I could not find any web posting with a similar issue.

Thanks in advance for your help,

Antonio

curtisraymond commented 1 year ago

I'm getting the same error message all of a sudden too!

mnmhouse commented 1 year ago

(base) [hadoop@jupyterlab-jupyter-prophot-1288-76c8d84f59-fq68p site-packages]$ python Python 3.7.6 | packaged by conda-forge | (default, Jun 1 2020, 18:57:50) [GCC 7.5.0] on linux Type "help", "copyright", "credits" or "license" for more information.

from prophet import Prophet Traceback (most recent call last): File "", line 1, in File "/opt/conda/lib/python3.7/site-packages/prophet/init.py", line 7, in from prophet.forecaster import Prophet File "/opt/conda/lib/python3.7/site-packages/prophet/forecaster.py", line 18, in from prophet.make_holidays import get_holiday_names, make_holidays_df File "/opt/conda/lib/python3.7/site-packages/prophet/make_holidays.py", line 14, in import prophet.hdays as hdays_part2 File "/opt/conda/lib/python3.7/site-packages/prophet/hdays.py", line 683, in class TU(Turkey): File "/opt/conda/lib/python3.7/site-packages/holidays/registry.py", line 178, in init super().init(*args, **kwargs) TypeError: object.init() takes exactly one argument (the instance to initialize)

michael72 commented 1 year ago

Getting the same error since this morning too!

longfei-wws commented 1 year ago

I am facing the same issue here. Even tried the historical releases up to "1.0", the final error is the same.

michael72 commented 1 year ago

Prophet has a dependency to holidays and they updated the library tonight If you set to use holidays version 0.24 explicitly in the requirements it should (hopefully) work again (at least it does for me!):

holidays==0.24
prophet==1.1.2
michael72 commented 1 year ago

hint at prophet guys: please replace the dependency "holidays>=0.14.2" to maybe "holidays==0.24" (or some other specific version) and file a bug at python holidays

longfei-wws commented 1 year ago

Prophet has a dependency to holidays and they updated the library tonight If you set to use version holidays version 0.24 in the requirements it should (hopefully) work again (at least it does for me!):

holidays==0.24
prophet==1.1.2

Hi Michael, thank you so much for this. The following works for me.

!{sys.executable} -m pip install "holidays==0.24"
import holidays

!{sys.executable} -m pip install "prophet==1.1.1"
from prophet import Prophet
akgarhwal commented 1 year ago

Prophet has a dependency to holidays and they updated the library tonight If you set to use holidays version 0.24 explicitly in the requirements it should (hopefully) work again (at least it does for me!):

holidays==0.24
prophet==1.1.2

Thanks Michael, this is working.

michael72 commented 1 year ago

relates to https://github.com/facebook/prophet/issues/2430

pushkingupta commented 1 year ago

Prophet has a dependency to holidays and they updated the library tonight If you set to use holidays version 0.24 explicitly in the requirements it should (hopefully) work again (at least it does for me!):

holidays==0.24
prophet==1.1.2

Thanks @michael72 , this worked for me as well.

apisani1 commented 1 year ago

Thank You All for your help.

PS:

I am running my environment on Apple Silicon. The above solution solved the import issue but after that I got another error when trying to fit my model:


RuntimeError Traceback (most recent call last) File ~/miniconda3/envs/tensorflow/lib/python3.10/site-packages/prophet/models.py:96, in CmdStanPyBackend.fit(self, stan_init, stan_data, kwargs) 95 try: ---> 96 self.stan_fit = self.model.optimize(args) 97 except RuntimeError as e: 98 # Fall back on Newton

File ~/miniconda3/envs/tensorflow/lib/python3.10/site-packages/cmdstanpy/model.py:738, in CmdStanModel.optimize(self, data, seed, inits, output_dir, sig_figs, save_profile, algorithm, init_alpha, tol_obj, tol_rel_obj, tol_grad, tol_rel_grad, tol_param, history_size, iter, save_iterations, require_converged, show_console, refresh, time_fmt, timeout) 737 else: --> 738 raise RuntimeError(msg) 739 mle = CmdStanMLE(runset)

RuntimeError: Error during optimization! Command '/Users/antonio/miniconda3/envs/tensorflow/lib/python3.10/site-packages/prophet/stan_model/prophet_model.bin random seed=49376 data file=/var/folders/0l/y4xmhw2139s23pj34w549fr80000gn/T/tmpycnwh7/6xxq4yd3.json init=/var/folders/0l/y4xmhw2139s23pj34w549fr80000gn/T/tmpycnwh7/kqml019w.json output file=/var/folders/0l/y4xmhw2139s23pj34w549fr80000gn/T/tmpycnwh7/prophet_modelf4h4ad6c/prophet_model-20230516110417.csv method=optimize algorithm=lbfgs iter=10000' failed: console log output:

dyld[38953]: Library not loaded: @rpath/libtbb.dylib Referenced from: /Users/antonio/miniconda3/envs/tensorflow/lib/python3.10/site-packages/prophet/stan_model/prophet_model.bin Reason: tried: '/private/var/folders/0l/y4xmhw2139s23pj34w549fr80000gn/T/pip-install-z7clm42v/prophet_cfeaa23011164fb4b9722c407627a5d7/build/lib.macosx-11.0-arm64-cpython-310/prophet/stan_model/cmdstan-2.26.1/stan/lib/stan_math/lib/tbb/libtbb.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/private/var/folders/0l/y4xmhw2139s23pj34w549fr80000gn/T/pip-install-z7clm42v/prophet_cfeaa23011164fb4b9722c407627a5d7/build/lib.macosx-11.0-arm64-cpython-310/prophet/stan_model/cmdstan-2.26.1/stan/lib/stan_math/lib/tbb/libtbb.dylib' (no such file), '/private/var/folders/0l/y4xmhw2139s23pj34w549fr80000gn/T/pip-install-z7clm42v/prophet_cfeaa23011164fb4b9722c407627a5d7/build/lib.macosx-11.0-arm64-cpython-310/prophet/stan_model/cmdstan-2.26.1/stan/lib/stan_math/lib/tbb/libtbb.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/private/var/folders/0l/y4xmhw2139s23pj34w549fr80000gn/T/pip-install-z7clm42v/prophet_cfeaa23011164fb4b9722c407627a5d7/build/lib.macosx-11.0-arm64-cpython-310/prophet/stan_model/cmdstan-2.26.1/stan/lib/stan_math/lib/tbb/libtbb.dylib' (no such file), '/usr/local/lib/libtbb.dylib' (no such file), '/usr/lib/libtbb.dylib' (no such file, not in dyld cache)

During handling of the above exception, another exception occurred:

RuntimeError Traceback (most recent call last) Cell In[21], line 1 ----> 1 m.fit(df_p)

File ~/miniconda3/envs/tensorflow/lib/python3.10/site-packages/prophet/forecaster.py:1174, in Prophet.fit(self, df, kwargs) 1172 self.params = self.stan_backend.sampling(stan_init, dat, self.mcmc_samples, kwargs) 1173 else: -> 1174 self.params = self.stan_backend.fit(stan_init, dat, **kwargs) 1176 self.stan_fit = self.stan_backend.stan_fit 1177 # If no changepoints were requested, replace delta with 0s

File ~/miniconda3/envs/tensorflow/lib/python3.10/site-packages/prophet/models.py:103, in CmdStanPyBackend.fit(self, stan_init, stan_data, kwargs) 101 logger.warning('Optimization terminated abnormally. Falling back to Newton.') 102 args['algorithm'] = 'Newton' --> 103 self.stan_fit = self.model.optimize(args) 104 params = self.stan_to_dict_numpy( 105 self.stan_fit.column_names, self.stan_fit.optimized_params_np) 106 for par in params:

File ~/miniconda3/envs/tensorflow/lib/python3.10/site-packages/cmdstanpy/model.py:738, in CmdStanModel.optimize(self, data, seed, inits, output_dir, sig_figs, save_profile, algorithm, init_alpha, tol_obj, tol_rel_obj, tol_grad, tol_rel_grad, tol_param, history_size, iter, save_iterations, require_converged, show_console, refresh, time_fmt, timeout) 736 get_logger().warning(msg) 737 else: --> 738 raise RuntimeError(msg) 739 mle = CmdStanMLE(runset) 740 return mle

RuntimeError: Error during optimization! Command '/Users/antonio/miniconda3/envs/tensorflow/lib/python3.10/site-packages/prophet/stan_model/prophet_model.bin random seed=47072 data file=/var/folders/0l/y4xmhw2139s23pj34w549fr80000gn/T/tmpycnwh7/0_cf3m7k.json init=/var/folders/0l/y4xmhw2139s23pj34w549fr80000gn/T/tmpycnwh7/g0fnf2ic.json output file=/var/folders/0l/y4xmhw2139s23pj34w549fr80000gn/T/tmpycnwh7/prophet_model2uesfiya/prophet_model-20230516110417.csv method=optimize algorithm=newton iter=10000' failed: console log output:

dyld[38954]: Library not loaded: @rpath/libtbb.dylib Referenced from: /Users/antonio/miniconda3/envs/tensorflow/lib/python3.10/site-packages/prophet/stan_model/prophet_model.bin Reason: tried: '/private/var/folders/0l/y4xmhw2139s23pj34w549fr80000gn/T/pip-install-z7clm42v/prophet_cfeaa23011164fb4b9722c407627a5d7/build/lib.macosx-11.0-arm64-cpython-310/prophet/stan_model/cmdstan-2.26.1/stan/lib/stan_math/lib/tbb/libtbb.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/private/var/folders/0l/y4xmhw2139s23pj34w549fr80000gn/T/pip-install-z7clm42v/prophet_cfeaa23011164fb4b9722c407627a5d7/build/lib.macosx-11.0-arm64-cpython-310/prophet/stan_model/cmdstan-2.26.1/stan/lib/stan_math/lib/tbb/libtbb.dylib' (no such file), '/private/var/folders/0l/y4xmhw2139s23pj34w549fr80000gn/T/pip-install-z7clm42v/prophet_cfeaa23011164fb4b9722c407627a5d7/build/lib.macosx-11.0-arm64-cpython-310/prophet/stan_model/cmdstan-2.26.1/stan/lib/stan_math/lib/tbb/libtbb.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/private/var/folders/0l/y4xmhw2139s23pj34w549fr80000gn/T/pip-install-z7clm42v/prophet_cfeaa23011164fb4b9722c407627a5d7/build/lib.macosx-11.0-arm64-cpython-310/prophet/stan_model/cmdstan-2.26.1/stan/lib/stan_math/lib/tbb/libtbb.dylib' (no such file), '/usr/local/lib/libtbb.dylib' (no such file), '/usr/lib/libtbb.dylib' (no such file, not in dyld cache)


I solved it by creating these symlinks:

sudo ln -s $HOME/miniconda3/envs/tensorflow/lib/python3.10/site-packages/prophet/stan_model/cmdstan-2.26.1/stan/lib/stan_math/lib/tbb/libtbb.dylib /usr/local/lib/libtbb.dylib

sudo ln -s $HOME/miniconda3/envs/tensorflow/lib/python3.10/site-packages/prophet/stan_model/cmdstan-2.26.1/stan/lib/stan_math/lib/tbb/libtbbmalloc.dylib /usr/local/lib/libtbbmalloc.dylib

sudo ln -s $HOME/miniconda3/envs/tensorflow/lib/python3.10/site-packages/prophet/stan_model/cmdstan-2.26.1/stan/lib/stan_math/lib/tbb/libtbbmalloc_proxy.dylib /usr/local/lib/libtbbmalloc_proxy.dylib

Vitorbnc commented 6 months ago

Just got this same issue here while using Darts RegressionModel module, @michael72's fix also worked for me.