英文:
How to build docker image with Facebook prophet library
问题
你的Docker构建失败是因为在构建prophet
时出现了一个错误,指出找不到numpy
模块。虽然你在requirements.txt
中包含了numpy
,但可能存在一些依赖关系或版本兼容性问题。
为了成功安装prophet
1.0.1,你可以尝试以下几个步骤:
- 在Docker文件的顶部,添加以下命令,以确保
numpy
和其他依赖项被正确安装:
RUN apt-get install -y python3-numpy
-
在
requirements.txt
中,将numpy
的版本指定为1.21.0,与你的要求文件中的版本一致。 -
重新运行
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
google-cloud-bigquery
google-cloud-storage
numpy==1.21.0
pandas==1.2.0
db-dtypes
plotly==5.10.0
hampel==0.0.5
prophet==1.0.1
click
joblib
scikit-learn
and here is my docker file -
FROM python:3.8-slim-buster as base
RUN mkdir my_dir
COPY requirements.txt /my_dir/requirements.txt
COPY src /my_dir/src
WORKDIR /my_dir
RUN apt update
RUN apt-get install -y --no-install-recommends \
ca-certificates \
cmake \
build-essential \
gcc \
g++ \
git \
curl \
apt-transport-https \
ca-certificates \
gnupg
RUN python -m pip install --no-cache-dir --upgrade setuptools pip wheel pipenv
RUN pip install -r requirements.txt
WORKDIR /my_dir/src
RUN python setup.py bdist_wheel
RUN pip install dist/*
# kubectl
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
RUN chmod +x ./kubectl
RUN mv ./kubectl /usr/local/bin
ENTRYPOINT [ "sh", "run.sh" ]
When I try to run docker-compose up -d
command, the build fails locally with below error -
13 25.10 Building wheels for collected packages: prophet, pymeeus
#13 25.10 Building wheel for prophet (setup.py): started
#13 25.40 Building wheel for prophet (setup.py): finished with status 'error'
#13 25.41 error: subprocess-exited-with-error
#13 25.41
#13 25.41 × python setup.py bdist_wheel did not run successfully.
#13 25.41 │ exit code: 1
#13 25.41 ╰─> [49 lines of output]
#13 25.41 running bdist_wheel
#13 25.41 running build
#13 25.41 running build_py
#13 25.41 creating build
#13 25.41 creating build/lib
#13 25.41 creating build/lib/prophet
#13 25.41 creating build/lib/prophet/stan_model
#13 25.41 Traceback (most recent call last):
#13 25.41 File "<string>", line 36, in <module>
#13 25.41 File "<pip-setuptools-caller>", line 34, in <module>
#13 25.41 File "/tmp/pip-install-l_l1ynvx/prophet_2f0894fc2ee74edfa49399ff3fb20863/setup.py", line 150, in <module>
#13 25.41 long_description_content_type='text/markdown',
#13 25.41 File "/usr/local/lib/python3.7/site-packages/setuptools/__init__.py", line 108, in setup
#13 25.41 return distutils.core.setup(**attrs)
#13 25.41 File "/usr/local/lib/python3.7/site-packages/setuptools/_distutils/core.py", line 185, in setup
#13 25.41 return run_commands(dist)
#13 25.41 File "/usr/local/lib/python3.7/site-packages/setuptools/_distutils/core.py", line 201, in run_commands
#13 25.41 dist.run_commands()
#13 25.41 File "/usr/local/lib/python3.7/site-packages/setuptools/_distutils/dist.py", line 969, in run_commands
#13 25.41 self.run_command(cmd)
#13 25.41 File "/usr/local/lib/python3.7/site-packages/setuptools/dist.py", line 1221, in run_command
#13 25.41 super().run_command(command)
#13 25.41 File "/usr/local/lib/python3.7/site-packages/setuptools/_distutils/dist.py", line 988, in run_command
#13 25.41 cmd_obj.run()
#13 25.41 File "/usr/local/lib/python3.7/site-packages/wheel/bdist_wheel.py", line 343, in run
#13 25.41 self.run_command("build")
#13 25.41 File "/usr/local/lib/python3.7/site-packages/setuptools/_distutils/cmd.py", line 318, in run_command
#13 25.41 self.distribution.run_command(command)
#13 25.41 File "/usr/local/lib/python3.7/site-packages/setuptools/dist.py", line 1221, in run_command
#13 25.41 super().run_command(command)
#13 25.41 File "/usr/local/lib/python3.7/site-packages/setuptools/_distutils/dist.py", line 988, in run_command
#13 25.41 cmd_obj.run()
#13 25.41 File "/usr/local/lib/python3.7/site-packages/setuptools/_distutils/command/build.py", line 131, in run
#13 25.41 self.run_command(cmd_name)
#13 25.41 File "/usr/local/lib/python3.7/site-packages/setuptools/_distutils/cmd.py", line 318, in run_command
#13 25.41 self.distribution.run_command(command)
#13 25.41 File "/usr/local/lib/python3.7/site-packages/setuptools/dist.py", line 1221, in run_command
#13 25.41 super().run_command(command)
#13 25.41 File "/usr/local/lib/python3.7/site-packages/setuptools/_distutils/dist.py", line 988, in run_command
#13 25.41 cmd_obj.run()
#13 25.41 File "/tmp/pip-install-l_l1ynvx/prophet_2f0894fc2ee74edfa49399ff3fb20863/setup.py", line 48, in run
#13 25.41 build_models(target_dir)
#13 25.41 File "/tmp/pip-install-l_l1ynvx/prophet_2f0894fc2ee74edfa49399ff3fb20863/setup.py", line 36, in build_models
#13 25.41 from prophet.models import StanBackendEnum
#13 25.41 File "/tmp/pip-install-l_l1ynvx/prophet_2f0894fc2ee74edfa49399ff3fb20863/prophet/__init__.py", line 8, in <module>
#13 25.41 from prophet.forecaster import Prophet
#13 25.41 File "/tmp/pip-install-l_l1ynvx/prophet_2f0894fc2ee74edfa49399ff3fb20863/prophet/forecaster.py", line 14, in <module>
#13 25.41 import numpy as np
#13 25.41 ModuleNotFoundError: No module named 'numpy'
#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
更改为以下内容:
google-cloud-bigquery
google-cloud-storage
numpy==1.21.0
pandas==1.2.0
db-dtypes
plotly==5.10.0
hampel==0.0.5
click
joblib
scikit-learn
pystan==2.19.1.1
Cython
cmdstanpy==0.9.68
matplotlib
LunarCalendar
convertdate
holidays
setuptools-git
python-dateutil
tqdm
(请注意,这里已删除prophet==1.0.1
。)然后将您的Dockerfile
更改为以下内容:
FROM python:3.8-slim-buster as base
RUN mkdir my_dir
COPY src /my_dir/src
WORKDIR /my_dir
RUN apt update
RUN apt-get install -y --no-install-recommends \
ca-certificates \
cmake \
build-essential \
gcc \
g++ \
git \
curl \
apt-transport-https \
ca-certificates \
gnupg
COPY requirements.txt /my_dir/requirements.txt
RUN python -m pip install --no-cache-dir --upgrade setuptools pip wheel pipenv
RUN pip install -r requirements.txt
RUN pip install prophet==1.0.1
WORKDIR /my_dir/src
RUN python setup.py bdist_wheel
RUN pip install dist/*
# kubectl
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
RUN chmod +x ./kubectl
RUN mv ./kubectl /usr/local/bin
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
google-cloud-bigquery
google-cloud-storage
numpy==1.21.0
pandas==1.2.0
db-dtypes
plotly==5.10.0
hampel==0.0.5
click
joblib
scikit-learn
pystan==2.19.1.1
Cython
cmdstanpy==0.9.68
matplotlib
LunarCalendar
convertdate
holidays
setuptools-git
python-dateutil
tqdm
(Note that prophet==1.0.1
has been removed here.) And then change your Dockerfile
to
FROM python:3.8-slim-buster as base
RUN mkdir my_dir
COPY src /my_dir/src
WORKDIR /my_dir
RUN apt update
RUN apt-get install -y --no-install-recommends \
ca-certificates \
cmake \
build-essential \
gcc \
g++ \
git \
curl \
apt-transport-https \
ca-certificates \
gnupg
COPY requirements.txt /my_dir/requirements.txt
RUN python -m pip install --no-cache-dir --upgrade setuptools pip wheel pipenv
RUN pip install -r requirements.txt
RUN pip install prophet==1.0.1
WORKDIR /my_dir/src
RUN python setup.py bdist_wheel
RUN pip install dist/*
# kubectl
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
RUN chmod +x ./kubectl
RUN mv ./kubectl /usr/local/bin
ENTRYPOINT [ "sh", "run.sh" ]
Alternatively, you could switch to a newer version of prophet that doesn't have this problem.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论