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.44k stars 4.53k forks source link

PyInstaller: AttributeError: 'Prophet' object has no attribute 'stan_backend' #1462

Closed laurencezabanal closed 1 year ago

laurencezabanal commented 4 years ago

I'm trying to create an executable file wherein my code imports fbprophet. It was successfully converted but upon running the function that calls fbprophet I'm getting an error of AttributeError: 'Prophet' object has no attribute 'stan_backend' anyone who encountered this? I'm using virtualenv and tried installing cython and pystan first before fbprophet.

Hopeful to hear from you guys. Python noob here as I'm originally using R

TahaBerkay commented 4 years ago

Same here..

Eudito commented 4 years ago

I found the same error when I was running my chunk. Please, any help?

bletham commented 4 years ago

The attribute stan_backend is set here: https://github.com/facebook/prophet/blob/8306ae3519d78581ab0a5c1a22954da09d6f2bda/python/fbprophet/forecaster.py#L143-L154

It seems that the pystan model is not being loaded correctly. To verify, could you run this and let me know what messages are printed out:

from fbprophet import Prophet
import logging
logger = logging.getLogger('fbprophet')
logger.setLevel(logging.DEBUG)

m = Prophet()
print(m.stan_backend)

The debug message should explain why it isn't loading the backend.

Eudito commented 4 years ago

Hi, this is the error:

AttributeError: 'Prophet' object has no attribute 'stan_backend'

Detailed traceback: 
  File "<string>", line 1, in <module>
  File "C:\Users\MAGUL\AppData\Local\r-miniconda\envs\r-reticulate\lib\site-packages\fbprophet\forecaster.py", line 141, in __init__
    self._load_stan_backend(stan_backend)
  File "C:\Users\MAGUL\AppData\Local\r-miniconda\envs\r-reticulate\lib\site-packages\fbprophet\forecaster.py", line 154, in _load_stan_backend
    logger.debug("Loaded stan backend: %s", self.stan_backend.get_type())
wxzwxz131 commented 4 years ago

same problem here

TahaBerkay commented 4 years ago

Hi All,

I have managed to solve this issue using hook files of PyInstaller.

  1. hook-fbprophet.py:
    
    from PyInstaller.utils.hooks import collect_submodules, collect_data_files

hiddenimports = collect_submodules('fbprophet') datas = collect_data_files('fbprophet')


2. hook-pystan.py:

from PyInstaller.utils.hooks import collect_submodules, collect_data_files

hiddenimports = collect_submodules('pystan') datas = collect_data_files('pystan')


3. hook-Cython.py:

from PyInstaller.utils.hooks import collect_submodules, collect_data_files

hiddenimports = collect_submodules('Cython') datas = collect_data_files('Cython')



Now, I could run my one-file executable without any problems.

**See:** https://pyinstaller.readthedocs.io/en/stable/hooks.html
**Note:** It also increases the size of the executable
Eudito commented 4 years ago

Hi Taha,

Well done, but I am not suceed. Look the error that return

ModuleNotFoundError: No module named 'PyInstaller'

Detailed traceback: 
  File "<string>", line 1, in <module>
campsbcn commented 4 years ago

Same problem

File "C:\Users\Patricia\AppData\Local\Programs\Python\Python37\lib\site-packages\fbprophet\forecaster.py", line 154, in _load_stan_backend
    logger.debug("Loaded stan backend: %s", self.stan_backend.get_type())
AttributeError: 'Prophet' object has no attribute 'stan_backend'
"
hudsondba commented 4 years ago

I solved this running the setup process: ` - wget https://github.com/stan-dev/cmdstan/releases/download/v2.22.1/cmdstan-2.22.1.tar.gz -O /tmp/cmdstan.tar.gz > /dev/null

eracle commented 4 years ago

Once installed with conda, you can copy paste the stan_model folder into the fbprophet directory. So it would not be necessary to compile again with pystan. You can search for the stan_model folder inside the "External Libraries" folder you have on the left on the IDE. Hope it helps

VinitSawant09 commented 4 years ago

Getting the same error. Any fix ?

File "C:\Users\Mypc\PycharmProjects\COVID19India\venv\lib\site-packages\fbprophet\forecaster.py", line 154, in _load_stan_backend logger.debug("Loaded stan backend: %s", self.stan_backend.get_type()) AttributeError: 'Prophet' object has no attribute 'stan_backend'

bletham commented 4 years ago

To be clear: This issue is about using PyInstaller to create a binary. If you're running into this error when not using PyInstaller, then it will probably be a different source and it'd be best to open a different issue.

fdmenendez commented 4 years ago

Any updates here?

acamargo96 commented 4 years ago

Hey guys,

For some reason, copying Cython's folder from Anaconda's site-packages folder to the executable's location solved this problem for me. Must be related to some pystan dependencies or to the way that pyinstaller locates them. Anyhow, hope it helps!

whidbey commented 4 years ago

Hi All,

I have managed to solve this issue using hook files of PyInstaller.

1. hook-fbprophet.py:
from PyInstaller.utils.hooks import collect_submodules, collect_data_files

hiddenimports = collect_submodules('fbprophet')
datas = collect_data_files('fbprophet')
1. hook-pystan.py:
from PyInstaller.utils.hooks import collect_submodules, collect_data_files

hiddenimports = collect_submodules('pystan')
datas = collect_data_files('pystan')
1. hook-Cython.py:
from PyInstaller.utils.hooks import collect_submodules, collect_data_files

hiddenimports = collect_submodules('Cython')
datas = collect_data_files('Cython')

Now, I could run my one-file executable without any problems.

See: https://pyinstaller.readthedocs.io/en/stable/hooks.html Note: It also increases the size of the executable

works great for me

QingguoC commented 4 years ago

Hi All, I have managed to solve this issue using hook files of PyInstaller.

1. hook-fbprophet.py:
from PyInstaller.utils.hooks import collect_submodules, collect_data_files

hiddenimports = collect_submodules('fbprophet')
datas = collect_data_files('fbprophet')
1. hook-pystan.py:
from PyInstaller.utils.hooks import collect_submodules, collect_data_files

hiddenimports = collect_submodules('pystan')
datas = collect_data_files('pystan')
1. hook-Cython.py:
from PyInstaller.utils.hooks import collect_submodules, collect_data_files

hiddenimports = collect_submodules('Cython')
datas = collect_data_files('Cython')

Now, I could run my one-file executable without any problems. See: https://pyinstaller.readthedocs.io/en/stable/hooks.html Note: It also increases the size of the executable

works great for me

Could you tell some more details of the versions of the modules? I had no luck on using these hooks for PyInstaller on Linux to build fbprophet model.

QingguoC commented 4 years ago

Hi All, I have managed to solve this issue using hook files of PyInstaller.

1. hook-fbprophet.py:
from PyInstaller.utils.hooks import collect_submodules, collect_data_files

hiddenimports = collect_submodules('fbprophet')
datas = collect_data_files('fbprophet')
1. hook-pystan.py:
from PyInstaller.utils.hooks import collect_submodules, collect_data_files

hiddenimports = collect_submodules('pystan')
datas = collect_data_files('pystan')
1. hook-Cython.py:
from PyInstaller.utils.hooks import collect_submodules, collect_data_files

hiddenimports = collect_submodules('Cython')
datas = collect_data_files('Cython')

Now, I could run my one-file executable without any problems. See: https://pyinstaller.readthedocs.io/en/stable/hooks.html Note: It also increases the size of the executable

works great for me

Could you tell some more details of the versions of the modules? I had no luck on using these hooks for PyInstaller on Linux to build fbprophet model.

Never mind. Problem got resolved. The hook method indeed worked.

abhinavk123 commented 3 years ago

Hi, Hooking method didn't work for me getting the same error .

DEBUG:fbprophet:Trying to load backend: PYSTAN DEBUG:fbprophet:Unable to load backend PYSTAN (DLL load failed: The specified module could not be found.), trying the next one DEBUG:fbprophet:Trying to load backend: CMDSTANPY DEBUG:fbprophet:Unable to load backend CMDSTANPY (no such file C:\Users\abhin\anaconda3\envs\timeseries\lib\site-packages\fbprophet\stan_model\prophet_model.bin), trying the next one

AttributeError Traceback (most recent call last)

in ----> 1 m = Prophet() 2 m.fit(train_x['sales']) ~\anaconda3\envs\timeseries\lib\site-packages\fbprophet\forecaster.py in __init__(self, growth, changepoints, n_changepoints, changepoint_range, yearly_seasonality, weekly_seasonality, daily_seasonality, holidays, seasonality_mode, seasonality_prior_scale, holidays_prior_scale, changepoint_prior_scale, mcmc_samples, interval_width, uncertainty_samples, stan_backend) 139 self.fit_kwargs = {} 140 self.validate_inputs() --> 141 self._load_stan_backend(stan_backend) 142 143 def _load_stan_backend(self, stan_backend): ~\anaconda3\envs\timeseries\lib\site-packages\fbprophet\forecaster.py in _load_stan_backend(self, stan_backend) 152 self.stan_backend = StanBackendEnum.get_backend_class(stan_backend)() 153 --> 154 logger.debug("Loaded stan backend: %s", self.stan_backend.get_type()) 155 156 def validate_inputs(self): AttributeError: 'Prophet' object has no attribute 'stan_backend'
bergen288 commented 3 years ago

I have the same error message "AttributeError: 'Prophet' object has no attribute 'stan_backend'" and tried various suggestions. My Python3.8.5 is installed with Anaconda on Windows 10.

  1. PyInstaller is installed before fbprophet with hook-Cython.py, hook-pystan.py, hook-fbprophet.py files defined in C:\Users\User\anaconda3\Lib\site-packages\PyInstaller\hooks per TahaBerkay's instruction. I still get error message. Do I miss something here?
  2. cmdstan-2.26.1.tar.gz is downloaded, unzipped. make -C /tmp/cmdstan-2.26.1/ build was completed successfully. What's the step of CMDSTAN=/tmp/cmdstan-2.22.1 STAN_BACKEND=CMDSTANPY python setup.py install? Why do we need python setup.py install here?

Any help is really appreciated.

Thanks.

bergen288 commented 3 years ago

I searched "stan_model" folder inside C:\Users\User\anaconda3 and found this one: C:\Users\User\anaconda3\pkgs\prophet-1.0.1-py38h43734a8_3\Lib\site-packages\prophet\stan_model. I copied it to C:\Users\User\anaconda3\Lib\site-packages\fbprophet and the issue is fixed.

Thanks.

lu159258 commented 3 years ago

please help me ,我遇到了这个问题

wangzhongqing commented 3 years ago

Hi All,

I have managed to solve this issue using hook files of PyInstaller.

  1. hook-fbprophet.py:
from PyInstaller.utils.hooks import collect_submodules, collect_data_files

hiddenimports = collect_submodules('fbprophet')
datas = collect_data_files('fbprophet')
  1. hook-pystan.py:
from PyInstaller.utils.hooks import collect_submodules, collect_data_files

hiddenimports = collect_submodules('pystan')
datas = collect_data_files('pystan')
  1. hook-Cython.py:
from PyInstaller.utils.hooks import collect_submodules, collect_data_files

hiddenimports = collect_submodules('Cython')
datas = collect_data_files('Cython')

Now, I could run my one-file executable without any problems.

See: https://pyinstaller.readthedocs.io/en/stable/hooks.html Note: It also increases the size of the executable

thank you, it helps me

forestbat commented 2 years ago

2283

WardBrian commented 1 year ago

Closing in favor of #2462