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

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

Error when installing Prophet in docker image

问题

我正在尝试安装Prophet,但是(只有在尝试通过镜像构建Docker时)会出现以下错误:

  1. 19.18 Collecting ujson (from cmdstanpy==0.9.68->prophet)
  2. 19.57 Downloading https://files.pythonhosted.org/packages/21/93/ba928551a83251be01f673755819f95a568cda0bfb9e0859be80086dce93/ujson-4.3.0.tar.gz (7.1MB)
  3. 23.28 Complete output from command python setup.py egg_info:
  4. 23.28 Traceback (most recent call last):
  5. 23.28 File "<string>", line 1, in <module>
  6. 23.28 File "/tmp/pip-build-hzpc95u_/ujson/setup.py", line 38, in <module>
  7. 23.28 "write_to_template": version_template,
  8. 23.28 File "/usr/lib/python3/dist-packages/setuptools/__init__.py", line 129, in setup
  9. 23.28 return distutils.core.setup(**attrs)
  10. 23.28 File "/usr/lib/python3.6/distutils/core.py", line 108, in setup
  11. 23.28 _setup_distribution = dist = klass(attrs)
  12. 23.28 File "/usr/lib/python3/dist-packages/setuptools/dist.py", line 372, in __init__
  13. 23.28 _Distribution.__init__(self, attrs)
  14. 23.28 File "/usr/lib/python3.6/distutils/dist.py", line 281, in __init__
  15. 23.28 self.finalize_options()
  16. 23.28 File "/usr/lib/python3/dist-packages/setuptools/dist.py", line 528, in finalize_options
  17. 23.28 ep.load()(self, ep.name, value)
  18. 23.28 File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2324, in load
  19. 23.28 return self.resolve()
  20. 23.28 File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2330, in resolve
  21. 23.28 module = __import__(self.module_name, fromlist=['__name__'], level=0)
  22. 23.28 File "/tmp/pip-build-hzpc95u_/ujson/.eggs/setuptools_scm-7.1.0-py3.6.egg/setuptools_scm/__init__.py", line 5
  23. 23.28 from __future__ import annotations
  24. 23.28 ^
  25. 23.28 SyntaxError: future feature annotations is not defined
  26. 23.28
  27. 23.28 ----------------------------------------
  28. 23.69 Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-hzpc95u_/ujson/
  29. ------
  30. 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如下:

  1. FROM ubuntu:18.04
  2. RUN apt-get update
  3. # To avoid the questions related to the geographic area
  4. RUN ln -snf /usr/share/zoneinfo/$CONTAINER_TIMEZONE /etc/localtime && echo $CONTAINER_TIMEZONE > /etc/timezone
  5. RUN apt-get install -y python3.10 python3-pip
  6. RUN pip3 install flask pandas numpy cython
  7. RUN python3 -m pip install prophet
  8. COPY app.py app.py
  9. COPY checks.py checks.py
  10. COPY predict.py predict.py
  11. EXPOSE 5000
  12. 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:

  1. 19.18 Collecting ujson (from cmdstanpy==0.9.68-&gt;prophet)
  2. 19.57 Downloading https://files.pythonhosted.org/packages/21/93/ba928551a83251be01f673755819f95a568cda0bfb9e0859be80086dce93/ujson-4.3.0.tar.gz (7.1MB)
  3. 23.28 Complete output from command python setup.py egg_info:
  4. 23.28 Traceback (most recent call last):
  5. 23.28 File &quot;&lt;string&gt;&quot;, line 1, in &lt;module&gt;
  6. 23.28 File &quot;/tmp/pip-build-hzpc95u_/ujson/setup.py&quot;, line 38, in &lt;module&gt;
  7. 23.28 &quot;write_to_template&quot;: version_template,
  8. 23.28 File &quot;/usr/lib/python3/dist-packages/setuptools/__init__.py&quot;, line 129, in setup
  9. 23.28 return distutils.core.setup(**attrs)
  10. 23.28 File &quot;/usr/lib/python3.6/distutils/core.py&quot;, line 108, in setup
  11. 23.28 _setup_distribution = dist = klass(attrs)
  12. 23.28 File &quot;/usr/lib/python3/dist-packages/setuptools/dist.py&quot;, line 372, in __init__
  13. 23.28 _Distribution.__init__(self, attrs)
  14. 23.28 File &quot;/usr/lib/python3.6/distutils/dist.py&quot;, line 281, in __init__
  15. 23.28 self.finalize_options()
  16. 23.28 File &quot;/usr/lib/python3/dist-packages/setuptools/dist.py&quot;, line 528, in finalize_options
  17. 23.28 ep.load()(self, ep.name, value)
  18. 23.28 File &quot;/usr/lib/python3/dist-packages/pkg_resources/__init__.py&quot;, line 2324, in load
  19. 23.28 return self.resolve()
  20. 23.28 File &quot;/usr/lib/python3/dist-packages/pkg_resources/__init__.py&quot;, line 2330, in resolve
  21. 23.28 module = __import__(self.module_name, fromlist=[&#39;__name__&#39;], level=0)
  22. 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. 23.28 from __future__ import annotations
  24. 23.28 ^
  25. 23.28 SyntaxError: future feature annotations is not defined
  26. 23.28
  27. 23.28 ----------------------------------------
  28. 23.69 Command &quot;python setup.py egg_info&quot; failed with error code 1 in /tmp/pip-build-hzpc95u_/ujson/
  29. ------
  30. 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:

  1. FROM ubuntu:18.04
  2. RUN apt-get update
  3. # To avoid the questions related to the geographic area
  4. RUN ln -snf /usr/share/zoneinfo/$CONTAINER_TIMEZONE /etc/localtime &amp;&amp; echo $CONTAINER_TIMEZONE &gt; /etc/timezone
  5. RUN apt-get install -y python3.10 python3-pip
  6. RUN pip3 install flask pandas numpy cython
  7. RUN python3 -m pip install prophet
  8. COPY app.py app.py
  9. COPY checks.py checks.py
  10. COPY predict.py predict.py
  11. EXPOSE 5000
  12. 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如下所示:

  1. FROM ubuntu:18.04
  2. ...
  3. RUN apt-get install -y python3.10 python3-pip
  4. RUN pip3 install --upgrade pip
  5. RUN pip3 install flask pandas numpy cython prophet
  6. ...
英文:

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:

  1. FROM ubuntu:18.04
  2. ...
  3. RUN apt-get install -y python3.10 python3-pip
  4. RUN pip3 install --upgrade pip
  5. RUN pip3 install flask pandas numpy cython prophet
  6. ...

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:

确定