Search code examples
pythonmatplotlibamazon-sagemakerfacebook-prophet

Import problem for Facebook Prophet on AWS Sagemaker


I am trying to use Facebook Prophet on an AWS Sagemaker Jupyter notebook. I've tried installing fbprophet in two ways:

!{sys.executable} -m pip install fbprophet

and

!conda install -c conda-forge fbprophet --yes

(that last one comes from several answers I saw on other forums)

However, none of them seem to work. In particular, the latest one seems to work for the installation, but the subsequent import of fbprophet results in an error, that seems related to matplotlib:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-8-d9f3d4c04a60> in <module>()
      1 # Imports
----> 2 from fbprophet import Prophet

~/anaconda3/envs/python3/lib/python3.6/site-packages/fbprophet/__init__.py in <module>()
      6 # of patent rights can be found in the PATENTS file in the same directory.
      7 
----> 8 from fbprophet.forecaster import Prophet
      9 
     10 __version__ = '0.6'

~/anaconda3/envs/python3/lib/python3.6/site-packages/fbprophet/forecaster.py in <module>()
     17 from fbprophet.make_holidays import get_holiday_names, make_holidays_df
     18 from fbprophet.models import StanBackendEnum
---> 19 from fbprophet.plot import (plot, plot_components)
     20 
     21 logger = logging.getLogger('fbprophet')

~/anaconda3/envs/python3/lib/python3.6/site-packages/fbprophet/plot.py in <module>()
     19 
     20 try:
---> 21     from matplotlib import pyplot as plt
     22     from matplotlib.dates import (
     23         MonthLocator,

~/anaconda3/envs/python3/lib/python3.6/site-packages/matplotlib/pyplot.py in <module>()
     30 from cycler import cycler
     31 import matplotlib
---> 32 import matplotlib.colorbar
     33 import matplotlib.image
     34 from matplotlib import rcsetup, style

~/anaconda3/envs/python3/lib/python3.6/site-packages/matplotlib/colorbar.py in <module>()
     25 
     26 import matplotlib as mpl
---> 27 import matplotlib.artist as martist
     28 import matplotlib.cbook as cbook
     29 import matplotlib.collections as collections

~/anaconda3/envs/python3/lib/python3.6/site-packages/matplotlib/artist.py in <module>()
     55 
     56 
---> 57 class Artist(object):
     58     """
     59     Abstract base class for objects that render into a FigureCanvas.

~/anaconda3/envs/python3/lib/python3.6/site-packages/matplotlib/artist.py in Artist()
     62     """
     63     @cbook.deprecated("3.1")
---> 64     @property
     65     def aname(self):
     66         return 'Artist'

~/anaconda3/envs/python3/lib/python3.6/site-packages/matplotlib/cbook/deprecation.py in deprecate(obj, message, name, alternative, pending, addendum)
    180                 pass
    181     """
--> 182 
    183     def deprecate(obj, message=message, name=name, alternative=alternative,
    184                   pending=pending, obj_type=obj_type, addendum=addendum):

AttributeError: 'property' object has no attribute '__name__'

Has anyone else run into this issue / managed to get fbprophet working on sagemaker? I'm thinking this might be an issue of versions of fbprophet and matplotlib, but couldn't find information on which ones to use.


Solution

  • The following works for me on a fresh notebook instance. I'm using the python3 environment.

    sh-4.2$ source activate python3
    (python3) sh-4.2$ conda install -c conda-forge fbprophet --yes
    Solving environment: done
    
    
    ==> WARNING: A newer version of conda exists. <==
      current version: 4.5.12
      latest version: 4.8.2
    
    Please update conda by running
    
        $ conda update -n base -c defaults conda
    
    
    
    ## Package Plan ##
    
      environment location: /home/ec2-user/anaconda3/envs/python3
    
      added / updated specs:
        - fbprophet
    
    
    The following packages will be downloaded:
    
        package                    |            build
        ---------------------------|-----------------
        pykerberos-1.2.1           |   py36h505690d_0          26 KB  conda-forge
        python-3.6.7               |    h381d211_1004        34.5 MB  conda-forge
        cryptography-2.8           |   py36h45558ae_2         628 KB  conda-forge
        python_abi-3.6             |          1_cp36m           4 KB  conda-forge
        binutils_impl_linux-64-2.33.1|       h53a641e_8         9.1 MB  conda-forge
        certifi-2019.11.28         |   py36h9f0ad1d_1         149 KB  conda-forge
        gcc_linux-64-7.3.0         |      h553295d_17          21 KB  conda-forge
        gxx_linux-64-7.3.0         |      h553295d_17          21 KB  conda-forge
        fbprophet-0.6              |   py36he1b5a44_0         642 KB  conda-forge
        holidays-0.10.1            |             py_0          56 KB  conda-forge
        tk-8.6.10                  |       hed695b0_0         3.2 MB  conda-forge
        lunarcalendar-0.0.9        |             py_0          20 KB  conda-forge
        convertdate-2.1.3          |          py_1000          30 KB  conda-forge
        curl-7.68.0                |       hf8cf82a_0         137 KB  conda-forge
        krb5-1.16.4                |       h2fd8d38_0         1.4 MB  conda-forge
        libcurl-7.68.0             |       hda55be3_0         564 KB  conda-forge
        expat-2.2.9                |       he1b5a44_2         191 KB  conda-forge
        binutils_linux-64-2.33.1   |      h9595d00_17          21 KB  conda-forge
        python-dateutil-2.8.0      |             py_0         219 KB  conda-forge
        matplotlib-base-3.1.0      |   py36h5f35d83_0         6.7 MB  conda-forge
        pycurl-7.43.0.5            |   py36h16ce93b_0          69 KB  conda-forge
        ld_impl_linux-64-2.33.1    |       h53a641e_8         589 KB  conda-forge
        pystan-2.17.1.0            |py36hf2d7682_1004        14.0 MB  conda-forge
        ephem-3.7.7.1              |   py36h516909a_0         722 KB  conda-forge
        ------------------------------------------------------------
                                               Total:        72.9 MB
    
    The following NEW packages will be INSTALLED:
    
        binutils_impl_linux-64: 2.33.1-h53a641e_8          conda-forge
        binutils_linux-64:      2.33.1-h9595d00_17         conda-forge
        convertdate:            2.1.3-py_1000              conda-forge
        ephem:                  3.7.7.1-py36h516909a_0     conda-forge
        fbprophet:              0.6-py36he1b5a44_0         conda-forge
        gcc_impl_linux-64:      7.3.0-habb00fd_1
        gcc_linux-64:           7.3.0-h553295d_17          conda-forge
        gettext:                0.19.8.1-hc5be6a0_1002     conda-forge
        gxx_impl_linux-64:      7.3.0-hdf63c60_1
        gxx_linux-64:           7.3.0-h553295d_17          conda-forge
        holidays:               0.10.1-py_0                conda-forge
        ld_impl_linux-64:       2.33.1-h53a641e_8          conda-forge
        lunarcalendar:          0.0.9-py_0                 conda-forge
        matplotlib-base:        3.1.0-py36h5f35d83_0       conda-forge
        pystan:                 2.17.1.0-py36hf2d7682_1004 conda-forge
        python_abi:             3.6-1_cp36m                conda-forge
    
    The following packages will be UPDATED:
    
        ca-certificates:        2019.10.16-0                           --> 2019.11.28-hecc5488_0     conda-forge
        certifi:                2019.9.11-py36_0                       --> 2019.11.28-py36h9f0ad1d_1 conda-forge
        cryptography:           2.2.2-py36h14c3975_0                   --> 2.8-py36h45558ae_2        conda-forge
        curl:                   7.60.0-h84994c4_0                      --> 7.68.0-hf8cf82a_0         conda-forge
        expat:                  2.2.5-he0dffb1_0                       --> 2.2.9-he1b5a44_2          conda-forge
        glib:                   2.56.1-h000015b_0                      --> 2.58.3-h6f030ca_1002      conda-forge
        krb5:                   1.14.2-hcdc1b81_6                      --> 1.16.4-h2fd8d38_0         conda-forge
        libcurl:                7.60.0-h1ad7b7a_0                      --> 7.68.0-hda55be3_0         conda-forge
        libpng:                 1.6.34-hb9fc6fc_0                      --> 1.6.37-hed695b0_0         conda-forge
        libssh2:                1.8.0-h9cfc8f7_4                       --> 1.8.2-h22169c7_2          conda-forge
        openssl:                1.0.2t-h7b6447c_1                      --> 1.1.1d-h516909a_0         conda-forge
        pycurl:                 7.43.0.1-py36hb7f436b_0                --> 7.43.0.5-py36h16ce93b_0   conda-forge
        pykerberos:             1.2.1-py36h14c3975_0                   --> 1.2.1-py36h505690d_0      conda-forge
        python:                 3.6.5-hc3d631a_2                       --> 3.6.7-h381d211_1004       conda-forge
        python-dateutil:        2.7.3-py36_0                           --> 2.8.0-py_0                conda-forge
        qt:                     5.9.6-h52aff34_0                       --> 5.9.7-h5867ecd_1
        sqlite:                 3.23.1-he433501_0                      --> 3.28.0-h8b20d00_0         conda-forge
        tk:                     8.6.7-hc745277_3                       --> 8.6.10-hed695b0_0         conda-forge
    
    
    Downloading and Extracting Packages
    pykerberos-1.2.1     | 26 KB     | ################################################################################ | 100%
    python-3.6.7         | 34.5 MB   | ################################################################################ | 100%
    cryptography-2.8     | 628 KB    | ################################################################################ | 100%
    python_abi-3.6       | 4 KB      | ################################################################################ | 100%
    binutils_impl_linux- | 9.1 MB    | ################################################################################ | 100%
    certifi-2019.11.28   | 149 KB    | ################################################################################ | 100%
    gcc_linux-64-7.3.0   | 21 KB     | ################################################################################ | 100%
    gxx_linux-64-7.3.0   | 21 KB     | ################################################################################ | 100%
    fbprophet-0.6        | 642 KB    | ################################################################################ | 100%
    holidays-0.10.1      | 56 KB     | ################################################################################ | 100%
    tk-8.6.10            | 3.2 MB    | ################################################################################ | 100%
    lunarcalendar-0.0.9  | 20 KB     | ################################################################################ | 100%
    convertdate-2.1.3    | 30 KB     | ################################################################################ | 100%
    curl-7.68.0          | 137 KB    | ################################################################################ | 100%
    krb5-1.16.4          | 1.4 MB    | ################################################################################ | 100%
    libcurl-7.68.0       | 564 KB    | ################################################################################ | 100%
    expat-2.2.9          | 191 KB    | ################################################################################ | 100%
    binutils_linux-64-2. | 21 KB     | ################################################################################ | 100%
    python-dateutil-2.8. | 219 KB    | ################################################################################ | 100%
    matplotlib-base-3.1. | 6.7 MB    | ################################################################################ | 100%
    pycurl-7.43.0.5      | 69 KB     | ################################################################################ | 100%
    ld_impl_linux-64-2.3 | 589 KB    | ################################################################################ | 100%
    pystan-2.17.1.0      | 14.0 MB   | ################################################################################ | 100%
    ephem-3.7.7.1        | 722 KB    | ################################################################################ | 100%
    Preparing transaction: done
    Verifying transaction: done
    Executing transaction: done
    (python3) sh-4.2$
    (python3) sh-4.2$
    (python3) sh-4.2$
    (python3) sh-4.2$ python
    Python 3.6.7 | packaged by conda-forge | (default, Feb 28 2019, 09:07:38)
    [GCC 7.3.0] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import fbprophet
    >>>