ModuleNotFoundError: No module named 'scipy' . I have imported scipy in requirements.txt still getting error

Url:https://theprasenjeet-movie-recommendation-movie-recommender-rxwu44.streamlitapp.com/

Error Log

[12:39:37] šŸ“¦ Processed dependencies!
  Stopping...



2022-09-01 12:39:40.655 Uncaught app exception
Traceback (most recent call last):
  File "/home/appuser/venv/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 556, in _run_script
    exec(code, module.__dict__)
  File "/app/movie_recommendation/movie_recommender.py", line 4, in <module>
    from script.recommender import contend_based_recommendations, weighted_average_based_recommendations, contend_based_recommendations_extra
  File "/app/movie_recommendation/script/recommender.py", line 1, in <module>
    import scipy
ModuleNotFoundError: No module named 'scipy'
[12:39:41] šŸ™ Pulling code changes from Github...
[12:39:41] šŸ”„ Updated app!
[12:39:42] šŸ“¦ Processing dependencies...
[12:39:42] šŸ“¦ Processed dependencies!
[12:39:45] šŸ”„ Updated app!
2022-09-01 12:40:22.279 Uncaught app exception
Traceback (most recent call last):
  File "/home/appuser/venv/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 556, in _run_script
    exec(code, module.__dict__)
  File "/app/movie_recommendation/movie_recommender.py", line 4, in <module>
    from script.recommender import contend_based_recommendations, weighted_average_based_recommendations, contend_based_recommendations_extra
  File "/app/movie_recommendation/script/recommender.py", line 1, in <module>
    import scipy
ModuleNotFoundError: No module named 'scipy'
[12:40:55] šŸ™ Pulling code changes from Github...
[12:40:56] šŸ“¦ Processing dependencies...
[12:40:56] šŸ“¦ Processed dependencies!
[12:40:57] šŸ”„ Updated app!

Hi @theprasenjeet, welcome to the community! :wave:

You should only use one requirements file for your app. Both environment.yml and requirements.txt exist in your repo. Pick one of them, delete the other, and try deleting and recreating your app on Streamlit Cloud.

1 Like

If I may add, Iā€™d suggest pinning a more recent version of Streamlit in your requirements.txt, say streamlit==1.12.2, so you can use the latest features and improvements. :smiley:

If you end up using environment.yml, take care to remove python and pip from the dependencies and any prefix you may have set. Installing python and pip via environment.yml will make it so that your dependencies get installed in a different virtual env than the one your app is running in. Meaning, you will continue to get ModuleNotFoundErrors.

A more general best practice: try including in your requirements file only packages that are actually used and imported in your app, rather than including everything from the output of pip freeze. :balloon: Makes debugging easier and reduces installation time.

1 Like

Thank you so much.It works !

1 Like