No module named sklearn

Hi, the streamlit app is working in my local machine, but when I deploy it gives error like no module named sklearn in I have entered scikit-learn in requirements.txt.Can u help please?
Github link:

File "/home/adminuser/venv/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/", line 552, in _run_script
    exec(code, module.__dict__)File "/mount/src/customerchurn/pages/", line 15, in <module>
    xgb_pipe = pickle.load(pickled_model)

what is the problem here?

Hi there @lalahashimli ,

Whenever you unpickle a model, remember to import the associated Python class beforehand. In your specific case, import the class of xgb_pipe before unpickling it.

Hope this helps!

Can u say in detailed, please? you mean I have to create class like in OOP? if yes , how can I do?
or I should import smth like from sklearn…

Can’t test right now, but try importing sklearn at the top of the file. Your xgb_pipe object needs to recognize the Pipeline class when it is unpickled, so maybe try:

from sklearn.pipeline import Pipeline

Let me know if it works!

It didn’t work .Now gives such error ModuleNotFoundError: No module named ‘sklearn’


File "/home/adminuser/venv/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/", line 552, in _run_script
    exec(code, module.__dict__)File "/mount/src/customerchurn/pages/", line 9, in <module>
    import sklearn

The versions of the some of packages like pandas ,numpy ,xgboost etc are different in streamlit cloud and in my jupyter notebook.Can it be the reason for this problem?

Hi again @lalahashimli ,

I just tested the page of your app in my local machine and it works. Make sure your requirements.txt has all the libraries and versions you need, so Streamlit Cloud takes them into account. Not specifying versions or specifying versions you haven’t tested is a common reason for errors.

It has been already solved. Thanks, again @marduk

1 Like

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