如何使用Facebook Prophet库构建Docker镜像。

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

How to build docker image with Facebook prophet library

问题

你的Docker构建失败是因为在构建prophet时出现了一个错误,指出找不到numpy模块。虽然你在requirements.txt中包含了numpy,但可能存在一些依赖关系或版本兼容性问题。

为了成功安装prophet 1.0.1,你可以尝试以下几个步骤:

  1. 在Docker文件的顶部,添加以下命令,以确保numpy和其他依赖项被正确安装:
  1. RUN apt-get install -y python3-numpy
  1. requirements.txt中,将numpy的版本指定为1.21.0,与你的要求文件中的版本一致。

  2. 重新运行docker-compose up -d来构建和启动你的Docker容器。

这些步骤应该有助于解决你遇到的问题并成功安装prophet 1.0.1。如果问题仍然存在,请确保你的环境中没有其他版本的numpy导致冲突。

英文:

I am trying to build a docker image with Prophet 1.0.1

Here is my requirements.txt file

  1. google-cloud-bigquery
  2. google-cloud-storage
  3. numpy==1.21.0
  4. pandas==1.2.0
  5. db-dtypes
  6. plotly==5.10.0
  7. hampel==0.0.5
  8. prophet==1.0.1
  9. click
  10. joblib
  11. scikit-learn

and here is my docker file -

  1. FROM python:3.8-slim-buster as base
  2. RUN mkdir my_dir
  3. COPY requirements.txt /my_dir/requirements.txt
  4. COPY src /my_dir/src
  5. WORKDIR /my_dir
  6. RUN apt update
  7. RUN apt-get install -y --no-install-recommends \
  8. ca-certificates \
  9. cmake \
  10. build-essential \
  11. gcc \
  12. g++ \
  13. git \
  14. curl \
  15. apt-transport-https \
  16. ca-certificates \
  17. gnupg
  18. RUN python -m pip install --no-cache-dir --upgrade setuptools pip wheel pipenv
  19. RUN pip install -r requirements.txt
  20. WORKDIR /my_dir/src
  21. RUN python setup.py bdist_wheel
  22. RUN pip install dist/*
  23. # kubectl
  24. RUN curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
  25. RUN chmod +x ./kubectl
  26. RUN mv ./kubectl /usr/local/bin
  27. ENTRYPOINT [ "sh", "run.sh" ]

When I try to run docker-compose up -d command, the build fails locally with below error -

  1. 13 25.10 Building wheels for collected packages: prophet, pymeeus
  2. #13 25.10 Building wheel for prophet (setup.py): started
  3. #13 25.40 Building wheel for prophet (setup.py): finished with status 'error'
  4. #13 25.41 error: subprocess-exited-with-error
  5. #13 25.41
  6. #13 25.41 × python setup.py bdist_wheel did not run successfully.
  7. #13 25.41 │ exit code: 1
  8. #13 25.41 ╰─> [49 lines of output]
  9. #13 25.41 running bdist_wheel
  10. #13 25.41 running build
  11. #13 25.41 running build_py
  12. #13 25.41 creating build
  13. #13 25.41 creating build/lib
  14. #13 25.41 creating build/lib/prophet
  15. #13 25.41 creating build/lib/prophet/stan_model
  16. #13 25.41 Traceback (most recent call last):
  17. #13 25.41 File "<string>", line 36, in <module>
  18. #13 25.41 File "<pip-setuptools-caller>", line 34, in <module>
  19. #13 25.41 File "/tmp/pip-install-l_l1ynvx/prophet_2f0894fc2ee74edfa49399ff3fb20863/setup.py", line 150, in <module>
  20. #13 25.41 long_description_content_type='text/markdown',
  21. #13 25.41 File "/usr/local/lib/python3.7/site-packages/setuptools/__init__.py", line 108, in setup
  22. #13 25.41 return distutils.core.setup(**attrs)
  23. #13 25.41 File "/usr/local/lib/python3.7/site-packages/setuptools/_distutils/core.py", line 185, in setup
  24. #13 25.41 return run_commands(dist)
  25. #13 25.41 File "/usr/local/lib/python3.7/site-packages/setuptools/_distutils/core.py", line 201, in run_commands
  26. #13 25.41 dist.run_commands()
  27. #13 25.41 File "/usr/local/lib/python3.7/site-packages/setuptools/_distutils/dist.py", line 969, in run_commands
  28. #13 25.41 self.run_command(cmd)
  29. #13 25.41 File "/usr/local/lib/python3.7/site-packages/setuptools/dist.py", line 1221, in run_command
  30. #13 25.41 super().run_command(command)
  31. #13 25.41 File "/usr/local/lib/python3.7/site-packages/setuptools/_distutils/dist.py", line 988, in run_command
  32. #13 25.41 cmd_obj.run()
  33. #13 25.41 File "/usr/local/lib/python3.7/site-packages/wheel/bdist_wheel.py", line 343, in run
  34. #13 25.41 self.run_command("build")
  35. #13 25.41 File "/usr/local/lib/python3.7/site-packages/setuptools/_distutils/cmd.py", line 318, in run_command
  36. #13 25.41 self.distribution.run_command(command)
  37. #13 25.41 File "/usr/local/lib/python3.7/site-packages/setuptools/dist.py", line 1221, in run_command
  38. #13 25.41 super().run_command(command)
  39. #13 25.41 File "/usr/local/lib/python3.7/site-packages/setuptools/_distutils/dist.py", line 988, in run_command
  40. #13 25.41 cmd_obj.run()
  41. #13 25.41 File "/usr/local/lib/python3.7/site-packages/setuptools/_distutils/command/build.py", line 131, in run
  42. #13 25.41 self.run_command(cmd_name)
  43. #13 25.41 File "/usr/local/lib/python3.7/site-packages/setuptools/_distutils/cmd.py", line 318, in run_command
  44. #13 25.41 self.distribution.run_command(command)
  45. #13 25.41 File "/usr/local/lib/python3.7/site-packages/setuptools/dist.py", line 1221, in run_command
  46. #13 25.41 super().run_command(command)
  47. #13 25.41 File "/usr/local/lib/python3.7/site-packages/setuptools/_distutils/dist.py", line 988, in run_command
  48. #13 25.41 cmd_obj.run()
  49. #13 25.41 File "/tmp/pip-install-l_l1ynvx/prophet_2f0894fc2ee74edfa49399ff3fb20863/setup.py", line 48, in run
  50. #13 25.41 build_models(target_dir)
  51. #13 25.41 File "/tmp/pip-install-l_l1ynvx/prophet_2f0894fc2ee74edfa49399ff3fb20863/setup.py", line 36, in build_models
  52. #13 25.41 from prophet.models import StanBackendEnum
  53. #13 25.41 File "/tmp/pip-install-l_l1ynvx/prophet_2f0894fc2ee74edfa49399ff3fb20863/prophet/__init__.py", line 8, in <module>
  54. #13 25.41 from prophet.forecaster import Prophet
  55. #13 25.41 File "/tmp/pip-install-l_l1ynvx/prophet_2f0894fc2ee74edfa49399ff3fb20863/prophet/forecaster.py", line 14, in <module>
  56. #13 25.41 import numpy as np
  57. #13 25.41 ModuleNotFoundError: No module named 'numpy'
  58. #13 25.41 [end of output]

I do have the numpy package included in the requirements.txt but it does not seem to work for me. How can I successfully install the prophet 1.0.1 using docker?

答案1

得分: 0

prophet 1.0.1似乎需要在构建包之前安装一些依赖项,因此您需要先安装这些依赖项。您可以将您的requirements.txt更改为以下内容:

  1. google-cloud-bigquery
  2. google-cloud-storage
  3. numpy==1.21.0
  4. pandas==1.2.0
  5. db-dtypes
  6. plotly==5.10.0
  7. hampel==0.0.5
  8. click
  9. joblib
  10. scikit-learn
  11. pystan==2.19.1.1
  12. Cython
  13. cmdstanpy==0.9.68
  14. matplotlib
  15. LunarCalendar
  16. convertdate
  17. holidays
  18. setuptools-git
  19. python-dateutil
  20. tqdm

(请注意,这里已删除prophet==1.0.1。)然后将您的Dockerfile更改为以下内容:

  1. FROM python:3.8-slim-buster as base
  2. RUN mkdir my_dir
  3. COPY src /my_dir/src
  4. WORKDIR /my_dir
  5. RUN apt update
  6. RUN apt-get install -y --no-install-recommends \
  7. ca-certificates \
  8. cmake \
  9. build-essential \
  10. gcc \
  11. g++ \
  12. git \
  13. curl \
  14. apt-transport-https \
  15. ca-certificates \
  16. gnupg
  17. COPY requirements.txt /my_dir/requirements.txt
  18. RUN python -m pip install --no-cache-dir --upgrade setuptools pip wheel pipenv
  19. RUN pip install -r requirements.txt
  20. RUN pip install prophet==1.0.1
  21. WORKDIR /my_dir/src
  22. RUN python setup.py bdist_wheel
  23. RUN pip install dist/*
  24. # kubectl
  25. RUN curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
  26. RUN chmod +x ./kubectl
  27. RUN mv ./kubectl /usr/local/bin
  28. ENTRYPOINT [ "sh", "run.sh" ]

或者,您可以切换到没有这个问题的新版本的prophet。

英文:

prophet 1.0.1 seems to need some of its dependencies before the package can been built, so you'll need to install those first. You can change your requirements.txt to

  1. google-cloud-bigquery
  2. google-cloud-storage
  3. numpy==1.21.0
  4. pandas==1.2.0
  5. db-dtypes
  6. plotly==5.10.0
  7. hampel==0.0.5
  8. click
  9. joblib
  10. scikit-learn
  11. pystan==2.19.1.1
  12. Cython
  13. cmdstanpy==0.9.68
  14. matplotlib
  15. LunarCalendar
  16. convertdate
  17. holidays
  18. setuptools-git
  19. python-dateutil
  20. tqdm

(Note that prophet==1.0.1 has been removed here.) And then change your Dockerfile to

  1. FROM python:3.8-slim-buster as base
  2. RUN mkdir my_dir
  3. COPY src /my_dir/src
  4. WORKDIR /my_dir
  5. RUN apt update
  6. RUN apt-get install -y --no-install-recommends \
  7. ca-certificates \
  8. cmake \
  9. build-essential \
  10. gcc \
  11. g++ \
  12. git \
  13. curl \
  14. apt-transport-https \
  15. ca-certificates \
  16. gnupg
  17. COPY requirements.txt /my_dir/requirements.txt
  18. RUN python -m pip install --no-cache-dir --upgrade setuptools pip wheel pipenv
  19. RUN pip install -r requirements.txt
  20. RUN pip install prophet==1.0.1
  21. WORKDIR /my_dir/src
  22. RUN python setup.py bdist_wheel
  23. RUN pip install dist/*
  24. # kubectl
  25. RUN curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
  26. RUN chmod +x ./kubectl
  27. RUN mv ./kubectl /usr/local/bin
  28. ENTRYPOINT [ "sh", "run.sh" ]

Alternatively, you could switch to a newer version of prophet that doesn't have this problem.

huangapple
  • 本文由 发表于 2023年4月20日 05:08:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/76058816.html
匿名

发表评论

匿名网友

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

确定