Search code examples
pythonpython-3.xdockerfacebook-prophet

Error when installing Prophet in docker image


I am trying to install prophet, yet (only when trying to docker build by image) the following error is thrown:

19.18 Collecting ujson (from cmdstanpy==0.9.68->prophet)
19.57   Downloading https://files.pythonhosted.org/packages/21/93/ba928551a83251be01f673755819f95a568cda0bfb9e0859be80086dce93/ujson-4.3.0.tar.gz (7.1MB)
23.28     Complete output from command python setup.py egg_info:
23.28     Traceback (most recent call last):
23.28       File "<string>", line 1, in <module>
23.28       File "/tmp/pip-build-hzpc95u_/ujson/setup.py", line 38, in <module>
23.28         "write_to_template": version_template,
23.28       File "/usr/lib/python3/dist-packages/setuptools/__init__.py", line 129, in setup
23.28         return distutils.core.setup(**attrs)
23.28       File "/usr/lib/python3.6/distutils/core.py", line 108, in setup
23.28         _setup_distribution = dist = klass(attrs)
23.28       File "/usr/lib/python3/dist-packages/setuptools/dist.py", line 372, in __init__
23.28         _Distribution.__init__(self, attrs)
23.28       File "/usr/lib/python3.6/distutils/dist.py", line 281, in __init__
23.28         self.finalize_options()
23.28       File "/usr/lib/python3/dist-packages/setuptools/dist.py", line 528, in finalize_options
23.28         ep.load()(self, ep.name, value)
23.28       File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2324, in load
23.28         return self.resolve()
23.28       File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2330, in resolve
23.28         module = __import__(self.module_name, fromlist=['__name__'], level=0)
23.28       File "/tmp/pip-build-hzpc95u_/ujson/.eggs/setuptools_scm-7.1.0-py3.6.egg/setuptools_scm/__init__.py", line 5
23.28         from __future__ import annotations
23.28         ^
23.28     SyntaxError: future feature annotations is not defined
23.28     
23.28     ----------------------------------------
23.69 Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-hzpc95u_/ujson/
------
failed to solve: process "/bin/sh -c python3 -m pip install prophet" did not complete successfully: exit code: 1

The above issue does not appear on my local execution. I have installed prophet using the pip install prophet command and everything works properly. The issue arises only when trying to create the Docker image.

The Dockerfile I use is the following:

FROM ubuntu:18.04
RUN apt-get update
# To avoid the questions related to the geographic area
RUN ln -snf /usr/share/zoneinfo/$CONTAINER_TIMEZONE /etc/localtime && echo $CONTAINER_TIMEZONE > /etc/timezone

RUN apt-get install -y python3.10 python3-pip
RUN pip3 install flask pandas numpy cython
RUN python3 -m pip install prophet

COPY app.py app.py
COPY checks.py checks.py
COPY predict.py predict.py

EXPOSE 5000

CMD ["python3", "-u", "app.py"]

I've tried also to install ujson and then try to install prophet. The ujson is installed yet afterwards the same issue arises.


Solution

  • The error because you're using an old version of the import of __future__ annotations as shown here https://peps.python.org/pep-0563/#enabling-the-future-behavior-in-python-3-7.

    Since you're using Python10, try to upgrade pip, so your Dockerfile becomes:

    FROM ubuntu:18.04
    ...
    RUN apt-get install -y python3.10 python3-pip
    RUN pip3 install --upgrade pip
    RUN pip3 install flask pandas numpy cython prophet
    ...