Error when deploying with docker

This is my Dockerfile.

FROM python:3.7
EXPOSE 8501
WORKDIR /app
COPY requirements.txt ./requirements.txt
RUN pip install -r requirements.txt
COPY . .
CMD streamlit run app.py

This is my requirements.txt.

pandas==1.0.3
numpy==1.18.3
streamlit==0.58.0
plotly==4.6.0
fbprophet==0.6
pybase64

Error that I got:

ERROR: Command errored out with exit status 1:
   command: /usr/local/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-cz44vw4i/fbprophet/setup.py'"'"'; __file__='"'"'/tmp/pip-install-cz44vw4i/fbprophet/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-a0rqx2kk
       cwd: /tmp/pip-install-cz44vw4i/fbprophet/
  Complete output (40 lines):
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib
  creating build/lib/fbprophet
  creating build/lib/fbprophet/stan_model
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "/tmp/pip-install-cz44vw4i/fbprophet/setup.py", line 148, in <module>
      """
    File "/usr/local/lib/python3.7/site-packages/setuptools/__init__.py", line 144, in setup
      return distutils.core.setup(**attrs)
    File "/usr/local/lib/python3.7/distutils/core.py", line 148, in setup
      dist.run_commands()
    File "/usr/local/lib/python3.7/distutils/dist.py", line 966, in run_commands
      self.run_command(cmd)
    File "/usr/local/lib/python3.7/distutils/dist.py", line 985, in run_command
      cmd_obj.run()
    File "/usr/local/lib/python3.7/site-packages/wheel/bdist_wheel.py", line 223, in run
      self.run_command('build')
    File "/usr/local/lib/python3.7/distutils/cmd.py", line 313, in run_command
      self.distribution.run_command(command)
    File "/usr/local/lib/python3.7/distutils/dist.py", line 985, in run_command
      cmd_obj.run()
    File "/usr/local/lib/python3.7/distutils/command/build.py", line 135, in run
      self.run_command(cmd_name)
    File "/usr/local/lib/python3.7/distutils/cmd.py", line 313, in run_command
      self.distribution.run_command(command)
    File "/usr/local/lib/python3.7/distutils/dist.py", line 985, in run_command
      cmd_obj.run()
    File "/tmp/pip-install-cz44vw4i/fbprophet/setup.py", line 48, in run
      build_models(target_dir)
    File "/tmp/pip-install-cz44vw4i/fbprophet/setup.py", line 36, in build_models
      from fbprophet.models import StanBackendEnum
    File "/tmp/pip-install-cz44vw4i/fbprophet/fbprophet/__init__.py", line 8, in <module>
      from fbprophet.forecaster import Prophet
    File "/tmp/pip-install-cz44vw4i/fbprophet/fbprophet/forecaster.py", line 14, in <module>
      import numpy as np
  ModuleNotFoundError: No module named 'numpy'
  ----------------------------------------
  ERROR: Failed building wheel for fbprophet

What is wrong? Thank you so much.

Hi @LLL, welcome to the Streamlit community!

Without trying this myself, I suspect its one of two problems. One, the pip resolver might not be working correctly to build your environment. You could try to remove the version number from numpy, in case fbprophet is looking for a specific numpy version. The second possibility could be the bigger issue of distributing compiled code using pip, which has historically been an issue (and why conda was created, to make sure the build toolchain for numpy and the like worked everywhere).

But try removing the numpy version first from requirements.txt.

I removed the version number from numpy.

pandas==1.0.3
numpy
streamlit==0.58.0
plotly==4.6.0
fbprophet==0.6
pybase64

I also tried including pystan.

pandas==1.0.3
numpy
streamlit==0.58.0
plotly==4.6.0
pystan==2.19.1.1
fbprophet==0.6
pybase64

In both cases, I’m getting back the same error. What else should I try?

The problem looks to be that fbprophet needs numpy in order to install not simply run.

I think you will need to run a pip install numpy (with version if you’d like) first, then install the rest of the dependencies.

EXPOSE 8501
WORKDIR /app
RUN pip install numpy==1.18.3
COPY requirements.txt ./requirements.txt
RUN pip install -r requirements.txt
COPY . .
CMD streamlit run app.py```
2 Likes

Had the very same issue and Ian Calvert’s suggestion solved it.
I also included the pandas dependency as well, as fb prophet in forecaster.py
imports numpy as well as pandas, so the dockerfile would look something like:

EXPOSE 8501
WORKDIR /app
RUN pip install numpy==1.18.5
RUN pip install pandas==1.0.4
RUN pip install convertdate==2.2.1
RUN pip install LunarCalendar==0.0.9
RUN pip install holidays==0.10.2
RUN pip install matplotlib==3.2.1
RUN pip install plotly==4.8.1
RUN pip install pystan==2.19.1.1
COPY requirements.txt ./requirements.txt
RUN pip install -r requirements.txt
COPY . .
CMD streamlit run app.py```

After that everything worked like a charm. To be honest I don’t know whether this is correct way to do it, however it works.

1 Like

Welcome to the community @samlidippos, and thanks for sharing! That doesn’t look unreasonable to me.