ModuleNotFoundError at Streamlit cloud

Hi all,
I noticed this question was asked multiple time, yet I’m still not sure how to solve my problem.
I have a python tool and I added a Streamlit interface to call it via subprocess,
this flow is working fine when running Streamlit locally, yet when trying to deploy it I’m getting “ModuleNotFoundError: No module named ‘numpy’” ,
I have numpy in the requirement.txt file and I can see in the log all dependencies are being installed correctly.
I set the numpy version in the requirement file numpy==2.1.2, I added a runtime.txt to set the python version python-3.12 , try rebooting, delete and redeploy, nothing worked.
I replace all numpy usage in the tool, just to get the same issue now with peewee
“ModuleNotFoundError: No module named ‘peewee’”

any suggestion on how to debug and overcome it?

Your deployed app runs in a virtual environment and you need to make sure the tool runs in the same environment. How to do that depends on the tool and how it needs to be called.

If you are the developer of the tool, I suggest you refactor it so that it can be used as a library and you don’t have to use subprocess.

Thanks, that solved the issues

Hi Goyo, calling it not as a subprocess solved the issue yet created a new issue.
all the imports and classes init I had in my tool are now get called only once, while my tool is build under the assumption that each instantiation of the tool all get re-initialized, and now I’m getting multiple failures from multiples places when I rerun the tool from streamlit.
all the singletons are holding values from previous run, a lists that was supposed to get initialized at init is now get leftovers from prev tests…

is there a solution for that? should I reload my modules each time?
Streamlit it now my main usage, so I’m a bit hesitate from entering mage restructure

Sure, there must be a solution. You should be able to change your code to make it call the import and classes init as many times as needed or work without that assumption.

Hi, I’m encountering the same issue deploying my app on Streamlit Cloud. Specifically when trying to import the ‘polars’ library in my app, it always fails. I’ve tried multiple solutions suggested in the community, but none have worked so far.

Here’s the error message displayed in the app:

ModuleNotFoundError: This app has encountered an error. The original error message is redacted to prevent data leaks. Full error details have been recorded in the logs (if you’re on Streamlit Cloud, click on ‘Manage app’ in the lower right of your app).

Traceback:

File "/mount/src/house-price-prediction/Home.py", line 21, in <module>
    page.run()File "/home/adminuser/.conda/lib/python3.12/site-packages/streamlit/navigation/page.py", line 303, in run
    exec(code, module.__dict__)File "/mount/src/house-price-prediction/Get_Started/2_House_Query.py", line 3, in <module>
    import polars as pl

github repo: GitHub - yrzheng0419/house-price-prediction: A project from the 'Advanced Urban Data Analytics and Modeling' course at the City Science Lab in Taipei Tech.
streamlit app: https://house-price-prediction-for-taipei-tw.streamlit.app/House_Query

Review your logs to see what happened while trying to install the packages in your requirements file.