ModuleNotFound when in dependencies file

I am getting a ModuleNotFound error for sklearn when deploying my streamlit app on the cloud. I am able to run the the file locally from my machine, and have verified that both scikit-learn and sklearn are in my Pipfile.lock along with the rest of my dependencies. Is there anything else I may be missing?

Here is the link to the repo: GitHub - aibromaghin/am_i_approved: ML-based web app to predict approval for consumer loan applications

Hi @Aiden_Bromaghin ,

have you created a requirements file? (App dependencies - Streamlit Docs)

@willhuang I have a pipfile.lock which lists my dependencies. As far as I can tell, this is supposed to take priority over requirements.txt files. Is this not compatible with streamlit?

I think I have always used requirements.txt so I was wondering maybe if you’ve tried that. It’s definitely legitimate to use a pipfile.lock.

Looking at the repo, it does look like those libraries are in the pipfile.lock.

Are there anymore useful logs in the terminal? Have you also tried restarting the app?

@willhuang I can try swapping out the .lock file for a requirements.txt file to see if that works any better. I’m not getting any other error in the logs, it just hits that line of code and throws the exception

Can you share the specific exception that is raised?

1 Like

Here it is

2022-10-25 16:15:58.056 Uncaught app exception
Traceback (most recent call last):
  File "/home/appuser/venv/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 562, in _run_script
    exec(code, module.__dict__)
  File "/app/am_i_approved/am_i_approved.py", line 6, in <module>
    import sklearn
ModuleNotFoundError: No module named 'sklearn'

A Pipfile is not the same as a Pipfile.lock. A Pipfile file lets you set up the requirements for packages using pipenv as the dependency manager, whereas a Pipfile.lock only specifies particular versions to be used of the packages listed in the Pipfile. But there is no Pipfile in the repo. Check here how to set up a Pipfile – notice that Pipfile.lock will be generated automatically:

Here is your app running on streamlit cloud: https://edsaac-am-i-approved-am-i-approved-bjgw8g.streamlitapp.com/ - (I also changed the way the pickled file was being loaded as it was never being closed :melting_face: )

@edsaac Got it, thank you! When I had read the pipenv docs, I saw that it recommended keeping both the pipfile and pipfile.lock in version control. Keeping both caused issues–I think it was looping between both dependency files–so I removed the pipfile and kept the pipfile.lock. I didn’t realize the pipfile.lock would be generated when the app was deployed. Thanks for the help!