Module not found when deploying streamlit via github

Hi,

I am getting the following error on my app:
ModuleNotFoundError: No module named ‘sklearn’

I have triple checked my requirements.txt, which specifies sklearn with the correct version, so am I at a loss about how to troubleshoot this issue.

Here is my app:
https://share.streamlit.io/mvantieghem/mcc_metastasis/master/live_app.py

Hi @mvantieghem, just double-checking on a possible easy solution. Have you tried having scikit-learn instead of sklearn in the requirements.txt?

Matteo

Hi Monchier, yes I jus tried that and same error. I don’t have to do anything to re-launch the app other than push the changes to github, correct?

Hi @mvantieghem!

From the logs, it looks like an error in the requirements.txt file:

Collecting absl-py==0.10.0
  Using cached absl_py-0.10.0-py3-none-any.whl (127 kB)
Collecting alabaster==0.7.12
  Using cached alabaster-0.7.12-py2.py3-none-any.whl (14 kB)
Requirement already up-to-date: altair==4.1.0 in /usr/local/lib/python3.7/site-packages (from -r requirements.txt (line 3)) (4.1.0)
Collecting applaunchservices==0.2.1
  Using cached applaunchservices-0.2.1-py3-none-any.whl (6.1 kB)
Collecting appnope==0.1.0
  Using cached appnope-0.1.0-py2.py3-none-any.whl (4.0 kB)
Collecting argh==0.26.2
  Using cached argh-0.26.2-py2.py3-none-any.whl (30 kB)
Processing /opt/concourse/worker/volumes/live/c4db8eed-7de0-4d68-400c-2ea7e21d3750/volume/argon2-cffi_1596828478065/work
ERROR: Could not install packages due to an EnvironmentError: [Errno 2] No such file or directory: '/opt/concourse/worker/volumes/live/c4db8eed-7de0-4d68-400c-2ea7e21d3750/volume/argon2-cffi_1596828478065/work'

2020-10-13 01:57:49,231 INFO exited: pip (exit status 1; not expected)

This error should be visible in the companion terminal on the app page. I suspect the error is due to the local path on your workstation not being available in Streamlit Sharing.

Hope this helps!


Amey

Hi Amey, thanks. I am not sure when the streamlit deployment instructions changed to use pipreqs to generate the requirements.txt, but that worked perfectly. My app is working!

Hi, I am also facing the same issue. I generated the requirements.txt file using pipreqs but I still get the same error.

Link to my app is https://share.streamlit.io/dhanyajothimani/sereadipity/sereadipity/sereadipity.py

It would be great if someone could give some suggestions/solutions.

Hi @dhanyajothimani -

Currently, Streamlit sharing requires the requirements.txt file to be at the top-level of the directory. So if you move/copy https://github.com/dhanyajothimani/SeREADipity/blob/master/sereadipity/requirements.txt to the top-level, your app should move past the library error.

Best,
Randy

Just to add to this thread. I had the same problem but it was resolved by using pipreq to generate the requirements.

I don’t know if it’s related but sklearn was the only module that installed into my local environment using pip, the rest were installed using miniconda

1 Like

Hi Randy,

That solved the error. However, I used git LFS to upload the csv file - does streamlit support this currently?

Git LFS is on our very short-term roadmap, I believe it will be available in February. For now, it won’t work on Streamlit sharing.

Git LFS should have gone out in the Streamlit sharing release this evening, please try it out and let us know if you have any issues.

Best,
Randy

can u guide me as to how can we move the requirements file to the top level of a directory

For No module named sklearn,

Try these:

  1. make sure the version of sklearn you used to create your model is the version of sklearn in your environment on anaconda. you can use pip show sklearn to see the version of your sklearn

  2. make sure you import all your dependencies at the top of your code

  3. add a requirements.txt file to your github repo that contains the dependencies used in your code. for instance i used: joblib==1.2.0
    numpy==1.26.1
    pandas==2.1.1
    Pillow==10.1.0
    scikit-learn==1.3.1
    scipy==1.11.3
    streamlit==1.27.2
    statsmodels

make sure the version of sklearn here is the version you used to create your model.

  1. make sure you add import sklearn in your web app file at the top

  2. if you have made all these changes and you are still getting the error, login to streamlit and delete the web app you are trying to deploy and start afresh. It should work seamlessly.