在 Docker 镜像中安装 Prophet 时出现错误。

huangapple go评论103阅读模式
英文:

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-&gt;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 &quot;&lt;string&gt;&quot;, line 1, in &lt;module&gt;
23.28       File &quot;/tmp/pip-build-hzpc95u_/ujson/setup.py&quot;, line 38, in &lt;module&gt;
23.28         &quot;write_to_template&quot;: version_template,
23.28       File &quot;/usr/lib/python3/dist-packages/setuptools/__init__.py&quot;, line 129, in setup
23.28         return distutils.core.setup(**attrs)
23.28       File &quot;/usr/lib/python3.6/distutils/core.py&quot;, line 108, in setup
23.28         _setup_distribution = dist = klass(attrs)
23.28       File &quot;/usr/lib/python3/dist-packages/setuptools/dist.py&quot;, line 372, in __init__
23.28         _Distribution.__init__(self, attrs)
23.28       File &quot;/usr/lib/python3.6/distutils/dist.py&quot;, line 281, in __init__
23.28         self.finalize_options()
23.28       File &quot;/usr/lib/python3/dist-packages/setuptools/dist.py&quot;, line 528, in finalize_options
23.28         ep.load()(self, ep.name, value)
23.28       File &quot;/usr/lib/python3/dist-packages/pkg_resources/__init__.py&quot;, line 2324, in load
23.28         return self.resolve()
23.28       File &quot;/usr/lib/python3/dist-packages/pkg_resources/__init__.py&quot;, line 2330, in resolve
23.28         module = __import__(self.module_name, fromlist=[&#39;__name__&#39;], level=0)
23.28       File &quot;/tmp/pip-build-hzpc95u_/ujson/.eggs/setuptools_scm-7.1.0-py3.6.egg/setuptools_scm/__init__.py&quot;, 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 &quot;python setup.py egg_info&quot; failed with error code 1 in /tmp/pip-build-hzpc95u_/ujson/
------
failed to solve: process &quot;/bin/sh -c python3 -m pip install prophet&quot; 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 &amp;&amp; echo $CONTAINER_TIMEZONE &gt; /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 [&quot;python3&quot;, &quot;-u&quot;, &quot;app.py&quot;]

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
...

huangapple
  • 本文由 发表于 2023年8月8日 20:44:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/76859705.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定