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

Created on 29 Apr 2020  路  18Comments  路  Source: facebook/prophet

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

Most helpful comment

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

All 18 comments

Same here..

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

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.

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())

same problem here

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

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>

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'
"

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

  • tar -xvf /tmp/cmdstan.tar.gz -C /tmp > /dev/null
  • make -C /tmp/cmdstan-2.22.1/ build > /dev/null
  • CMDSTAN=/tmp/cmdstan-2.22.1 STAN_BACKEND=CMDSTANPY python setup.py install`

I have same problem. It seems appear when prophet try to do more than one forecast at the same time at least in my scenario which uses Flask to run an API server.

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

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'

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.

Any updates here?

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!

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

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.

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.

Was this page helpful?
0 / 5 - 0 ratings