英文:
Error when installing Prophet in docker image
问题
我正在尝试安装Prophet,但是(只有在尝试通过镜像构建Docker时)会出现以下错误:
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
上述问题在我本地执行时没有出现。我已经使用pip install prophet
命令安装了Prophet,并且一切正常。只有在尝试创建Docker镜像时才会出现问题。
我使用的Dockerfile如下:
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"]
我还尝试安装了ujson
,然后再尝试安装Prophet。ujson
已经安装,但之后出现了相同的问题。
英文:
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.
答案1
得分: 1
错误是因为您正在使用旧版本的__future__ annotations
导入,如此处所示:https://peps.python.org/pep-0563/#enabling-the-future-behavior-in-python-3-7。
由于您正在使用Python10,请尝试升级pip,使您的Dockerfile如下所示:
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
...
英文:
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
...
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论