ModuleNotFoundError: No module named 'shap'

Hi all,

I’m deploying a machine learning model on share Streamlit through a flask API. Everything worked fine since a few days ago and I don’t know why since this afternoon share streamlit is crashing : I have a ModuleNotFoundError.

Following is the error message I get from the log:
[manager] Python dependencies were installed from /app/openclassrooms-p7/requirements.txt using pip.
[manager] Processed dependencies!
2022-02-01 11:04:05.524 Uncaught app exception
Traceback (most recent call last):
File “/home/appuser/venv/lib/python3.8/site-packages/streamlit/script_runner.py”, line 379, in _run_script
exec(code, module.dict)
File “/app/openclassrooms-p7/app.py”, line 3, in
import shap
ModuleNotFoundError: No module named ‘shap’

However, this library does figure in my requirements.txt (plus I did not change anything yet in my GitHub repo so I don’t understand why it would suddenly not work):
pandas==1.3.5
flask==1.1.2
streamlit==1.3.1
numpy==1.21.2
plotly==5.5.0
scikit-learn==1.0.1
requests==2.27.1
shap==0.40.0
matplotlib==3.5.0
alibi==0.6.2

Here is the GitHub repo of the project:

I already followed the documentation in the following page (ModuleNotFoundError No module named - Streamlit Docs) and the previous comments on similar posts, but I am still lost.

Would you have any clue about my issue?

Many thanks for your help.
Regards,
Antoine

Hi @antoine-mle, welcome to the community! :wave: :partying_face:

Would you mind deleting your app on Streamlit Cloud and redeploying it? I was able to successfully deploy a fork of your app:

Best, :balloon:
Snehan

Hi Snehan,

Thanks a lot for you quick reply. I just deleted the app and redeployed it however I still face the same issue about the module ‘shap’. Would you know what I should do?

Best regards, and thanks again for your help.
Antoine

I solved this issue by replacing the versions of all the libraries in the requirements.txt file with their latest versions. Also, as I can see in your screenshot, pip is looking for multiple versions of the same library (like cffi). This was also automatically solved when I upgraded the libraries.

Also, I changed the python version from 3.7 to 3.9 in advanced options while deploying.

I all,
I deleted my app and redeployed it choosing python version 3.9. I also amended my requirements.txt file to update the latest versions of each library :
pandas==1.4.0
flask==2.0.2
streamlit==1.5.0
numpy==1.22.1
plotly==5.5.0
scikit-learn==1.0.2
requests==2.27.1
shap==0.40.0
matplotlib==3.5.1
alibi==0.6.4

However I still face the same problem because of ‘shap’. Would you know the cause of this issue? I’m still lost…
Sorry for disturbing you guys…

Many thanks,
Antoine

Ok, I made a new deletion and a new deployment and it seems to work. I don’t have any clue why… :slight_smile:

Many thanks Kanak & Snehan for your help and time!
Have a good one,
Antoine

1 Like

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