Flask package is not working in Streamlit Sharing


I’ve been using Streamlit Sharing for one of way to deploy the app.
However, it seems that SS doesn’t support Flask package as it returns error message.
It worked well locally but only had a problem in SS.

Can anyone let me know how to resolve this out?

My app is https://share.streamlit.io/djshan1979/webtools-fitbit4food/main/fitbit4food_prototype.py

The error message just said
" ```
[manager] Python dependencies were installed from /app/webtools-fitbit4food/requirements.txt using pip.
[manager] installer returned a non-zero exit code
[manager] Error during processing dependencies! Please fix the error and push an update, or try restarting the app.

1 Like

Hi @djshan1979,

Happy to help :slight_smile: When I forked your repo and deployed to sharing, this is the error I saw in the logs:

[manager] Python dependencies were installed from /app/webtools-fitbit4food/requirements.txt using pip.
[manager] Processed dependencies!
2021-07-08 05:05:41.679 An update to the [server] config option section was detected. To have these changes be reflected, please restart streamlit.
Traceback (most recent call last):
  File "reinforcement_engine.py", line 3, in <module>
    from flask import Flask, request, make_response
ModuleNotFoundError: No module named 'flask'

Another log message indicated that the flask package was successfully installed from the requirements file:

Successfully installed Inflect-5.3.0 MarkupSafe-2.0.1 Send2Trash-1.7.1 Werkzeug-2.0.1 altair-4.1.0 argon2-cffi-20.1.0 astor-0.8.1 async-generator-1.10 attrs-21.2.0 backcall-0.2.0 base58-2.1.0 bleach-3.3.0 blinker-1.4 cachetools-4.2.2 certifi-2021.5.30 cffi-1.14.5 chardet-4.0.0 click-8.0.1 debugpy-1.3.0 decorator-5.0.9 defusedxml-0.7.1 entrypoints-0.3 flask-2.0.1 flask-cors-3.0.10

While it initially seems contradictory, there’s a straightforward explanation:

  1. The packages in your requirements file are installed in a virtual environment. The Python binary used in this virtual env is found at /home/appuser/venv/bin/python

  2. In line 584 of your app, you run python reinforcement_engine.py via a subprocess. This Python binary is not the one used in the virtual env where your packages, including flask, are installed.

  3. Change line 584 to the following:

    subprocess.Popen(['/home/appuser/venv/bin/python', 'reinforcement_engine.py'], close_fds=True)
  4. Reboot your app

Once you make the change :point_up: you should not see the flask related import error:

Happy Streamlit’ing! :balloon:


Hi Snehan, @snehankekre
I have one question.
It’s gives error “connection refuse” from flask request.
What should we need to use instead of “” ?

Hi @snehankekre
Thanks for your response, I’ve tried to do just following your guidance. However, it still has the same issue on my Streamlit sharing.
I think it might be a different reason to cause the issue or
the path above /home/appuser/venv/bin/python would be different to mine.

Please let me get out of this issue