Pystan issues while deploying an app on share.streamlit.io

Hey folks, hope someone can throw some insights here, the app works fine on my local, which is mac OS 12.0.1 but while I try to deploy it on streamlit cloud I get the following error, full traceback is too long, everything before this error traceback is related to copying…

        running build_ext

        building 'pystan._api' extension

        Warning: Can't read registry to find the necessary compiler setting

        Make sure that Python modules winreg, win32api or win32con are installed.

        INFO: C compiler: gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC

        

        creating build/temp.linux-x86_64-3.9

        creating build/temp.linux-x86_64-3.9/pystan

        creating build/temp.linux-x86_64-3.9/pystan/stan

        creating build/temp.linux-x86_64-3.9/pystan/stan/src

        creating build/temp.linux-x86_64-3.9/pystan/stan/src/stan

        creating build/temp.linux-x86_64-3.9/pystan/stan/src/stan/lang

        creating build/temp.linux-x86_64-3.9/pystan/stan/src/stan/lang/grammars

        INFO: compile options: '-DBOOST_DISABLE_ASSERTS -DBOOST_NO_DECLTYPE -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -DBOOST_RESULT_OF_USE_TR1 -DFUSION_MAX_VECTOR_SIZE=12 -I./pystan -Ipystan/stan/src -Ipystan/stan/lib/stan_math/ -Ipystan/stan/lib/stan_math/lib/eigen_3.3.3 -Ipystan/stan/lib/stan_math/lib/boost_1.69.0 -Ipystan/stan/lib/stan_math/lib/sundials_4.1.0/include -I/home/appuser/venv/include -I/usr/local/include/python3.9 -c'

        extra options: '-Os -ftemplate-depth-256 -Wno-unused-function -Wno-uninitialized -std=c++1y'

        INFO: gcc: pystan/_api.cpp

        INFO: gcc: pystan/stan/src/stan/lang/grammars/block_var_decls_grammar_inst.cpp

        INFO: gcc: pystan/stan/src/stan/lang/grammars/expression_grammar_inst.cpp

        INFO: gcc: pystan/stan/src/stan/lang/grammars/expression07_grammar_inst.cpp

        INFO: gcc: pystan/stan/src/stan/lang/grammars/functions_grammar_inst.cpp

        INFO: gcc: pystan/stan/src/stan/lang/grammars/bare_type_grammar_inst.cpp

        INFO: gcc: pystan/stan/src/stan/lang/grammars/indexes_grammar_inst.cpp

        INFO: gcc: pystan/stan/src/stan/lang/ast_def.cpp

        gcc: fatal error: Killed signal terminated program cc1plus

        compilation terminated.

        INFO: gcc: pystan/stan/src/stan/lang/grammars/local_var_decls_grammar_inst.cpp

        gcc: fatal error: Killed signal terminated program cc1plus

        compilation terminated.

        INFO: gcc: pystan/stan/src/stan/lang/grammars/program_grammar_inst.cpp

        gcc: fatal error: Killed signal terminated program cc1plus

        compilation terminated.

        INFO: gcc: pystan/stan/src/stan/lang/grammars/semantic_actions_def.cpp

        gcc: fatal error: Killed signal terminated program cc1plus

        compilation terminated.

        INFO: gcc: pystan/stan/src/stan/lang/grammars/statement_2_grammar_inst.cpp

        gcc: fatal error: Killed signal terminated program cc1plus

        compilation terminated.

        INFO: gcc: pystan/stan/src/stan/lang/grammars/statement_grammar_inst.cpp

        gcc: fatal error: Killed signal terminated program cc1plus

        compilation terminated.

        INFO: gcc: pystan/stan/src/stan/lang/grammars/term_grammar_inst.cpp

        gcc: fatal error: Killed signal terminated program cc1plus

        compilation terminated.

        INFO: gcc: pystan/stan/src/stan/lang/grammars/whitespace_grammar_inst.cpp

        gcc: fatal error: Killed signal terminated program cc1plus

        compilation terminated.

        gcc: fatal error: Killed signal terminated program cc1plus

        compilation terminated.

        gcc: fatal error: Killed signal terminated program cc1plus

        compilation terminated.

        gcc: fatal error: Killed signal terminated program cc1plus

        compilation terminated.

        gcc: fatal error: Killed signal terminated program cc1plus

        compilation terminated.

        gcc: fatal error: Killed signal terminated program cc1plus

        compilation terminated.

        error: Command "gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -DBOOST_DISABLE_ASSERTS -DBOOST_NO_DECLTYPE -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -DBOOST_RESULT_OF_USE_TR1 -DFUSION_MAX_VECTOR_SIZE=12 -I./pystan -Ipystan/stan/src -Ipystan/stan/lib/stan_math/ -Ipystan/stan/lib/stan_math/lib/eigen_3.3.3 -Ipystan/stan/lib/stan_math/lib/boost_1.69.0 -Ipystan/stan/lib/stan_math/lib/sundials_4.1.0/include -I/home/appuser/venv/include -I/usr/local/include/python3.9 -c pystan/_api.cpp -o build/temp.linux-x86_64-3.9/pystan/_api.o -Os -ftemplate-depth-256 -Wno-unused-function -Wno-uninitialized -std=c++1y" failed with exit status 1

        [end of output]

    

    note: This error originates from a subprocess, and is likely not a problem with pip.

  error: legacy-install-failure

  

  × Encountered error while trying to install package.

  ╰─> pystan

  

  note: This is an issue with the package mentioned above, not pip.

  hint: See above for output from the failure.

  WARNING: You are using pip version 22.0.3; however, version 22.0.4 is available.

  You should consider upgrading via the '/home/appuser/venv/bin/python -m pip install --upgrade pip' command.

  

  at ~/.poetry/lib/poetry/utils/env.py:1195 in _run

      1191│                 output = subprocess.check_output(

      1192│                     cmd, stderr=subprocess.STDOUT, **kwargs

      1193│                 )

      1194│         except CalledProcessError as e:

    → 1195│             raise EnvCommandError(e, input=input_)

      1196│ 

      1197│         return decode(output)

      1198│ 

      1199│     def execute(self, bin, *args, **kwargs):

/app/climate-trydan

the app I am trying to build using poetry is here @ GitHub - ybangaru/climate-trydan
I did see some similar posts around and updated pystan using “poetry add pystan@2.19.1.1” and the other thing I did was updating config.toml to use [server] port=8501 besides the [theme]. None of them helped, any thoughts on what might I be missing here? Thank you!

Just a quick idea. You use prophet, which in turn requires pystan.
I don’t know how poetry handles dependencies, but I would put pystan before prophet in the list of your pyproject.toml file.

Another idea: pystan needs a compiler for installation:

C++ compiler: gcc ≥9.0 or clang ≥10.0

I don’t know if and which compiler version is installed by default on the streamlit sharing runtime.

EDIT: The compiler should not be the problem, because gcc 10.2.1 seems to be preinstalled in the runtime.

Hi @yash,

I was unable to install prophet and pystan via poetry and conda. What worked was installation via requirements.txt. Here are the steps needed to get your app working:

  1. Delete your app on Streamlit Cloud
  2. Delete or rename pyproject.toml
  3. Delete or rename poetry.lock
  4. Create a requirements.txt file in the root of your repo, containing the following:
    pandas >= 1.3.5
    jupyter >= 1.0.0
    ipykernel >= 6.6.1
    lxml >= 4.7.1
    plotly >= 5.5.0
    streamlit >= 1.3.1
    scipy
    seaborn >= 0.11.2
    sklearn
    pystan == 2.19.1.1
    fbprophet == 0.7.1
    
    pytest >= 5.2
    flake8 >= 4.0.1
    mypy >= 0.930
    black >= 21.12b0
    
  5. Change line 15 of your app (import prophet…) to from fbprophet import Prophet
  6. Set data_root in line 22 of your app to data_root = "climate_trydan/data"
  7. Redeploy your app and use Python 3.7.

Once you make the above changes, your app should work as expected:

Here’s my fork of your repo with the above changes.

Best,
Snehan

1 Like

@snehankekre
Just a quick side note: The package fbprophet seems to be quite old in the pypi repository, i think the latest package is called prophet now in pypi, as the docs also say:

GitHub - facebook/prophet: Tool for producing high quality forecasts for time series data that has multiple seasonality with linear or non-linear growth.

1 Like

I failed to install prophet via any means :sweat_smile: And while the package is old, the model @yash uses is identical in fbprophet, so it shouldn’t be an issue IMO.

Really appreciate the help here @snehankekre, it works, just sad that I can’t use poetry package manager as it is and had to downgrade a package, hope streamlit can make it work out of the box in the future :slight_smile:

@snehankekre
Unfortunately, it looks like you’re right… :grimacing:
The installation of pystan and prophet is currently a real pain in the a@@.
I tried it locally with Docker and found a solution, that throws no errors during installation, see Dockerfile below.

However, this will not work on Streamlit Cloud, as I am using a three-step pip installation.
I wouldn’t know how to get this to work on Streamlit Cloud and I can’t think of a workaround so far. :thinking:

FROM python:3.9-slim

# we probably need build tools?
RUN apt-get update \
    && apt-get install --yes --no-install-recommends \
    build-essential

# we need the requirements.txt file from prophet to be in the root of the project
# https://github.com/facebook/prophet/blob/main/python/requirements.txt
WORKDIR /app
COPY . .

# first: install all required packages for pystan
RUN pip install --no-cache-dir --upgrade cython numpy
# second: install all required packages for prophet from their requirements.txt
RUN pip install --no-cache-dir --upgrade -r requirements.txt
# third: install prophet itself
RUN pip install --no-cache-dir --upgrade prophet
1 Like

@yash @Franky1

I was dealing with this issue – installing pystan/prophet – and had a potential solve in the works that I was crossing my fingers would work when deploying. Was alerted to this thread and was fearful it wasn’t going to work but just finally deployed the app today without a hitch. See below for the pypoetry.toml noting the install of httpstan via url which seemed to be the issue in installing pystan on unix (Ubuntu WSL2 on Windows). The pypi_ source may not be necessary and is a holdover of trying to point poetry to pypi to find httpstan before going the direct url route. Finally, note this likely won’t work on Windows as there appear to only be wheels for unix.

Hope it works for you all!

[tool.poetry]
name = "some_tool"
version = "0.1.0"
description = "some_description"
authors = ["Your Name <you@example.com>"]

[[tool.poetry.source]]
name = 'pypi_'  # needed until python-poetry/poetry#3456 is resolved.
url = 'https://pypi.org/simple'
secondary = false

[tool.poetry.dependencies]
python = "^3.8"
httpstan = {url = "https://files.pythonhosted.org/packages/8e/69/754b27a6191d77d56ae39ad39013781d4db3e44bc631169f4f0d2f2ab821/httpstan-4.7.2-cp38-cp38-manylinux_2_24_x86_64.whl"}
pystan = "2.19.1.1"
prophet = "1.0.1"
streamlit = "^1.8.1"
plotly = "^5.6.0"

[tool.poetry.dev-dependencies]

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"