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

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.