I have sklearn version 0.24.1 but it is showing me this error in my streamlit app....don't know how to solve this

ModuleNotFoundError: No module named 'sklearn.linear_model._logistic'
File "c:\users\chintan\appdata\local\programs\python\python37\lib\site-packages\streamlit\script_runner.py", line 332, in _run_script
    exec(code, module.__dict__)
File "C:\Users\chintan\Desktop\streamlit\Final_year_project\App.py", line 317, in <module>
File "C:\Users\chintan\Desktop\streamlit\Final_year_project\App.py", line 252, in main
    loaded_model = load_model("logistic_regression_model.pkl")
File "C:\Users\chintan\Desktop\streamlit\Final_year_project\App.py", line 84, in load_model
    loaded_model = joblib.load(open(os.path.join(model_file),"rb"))
File "c:\users\chintan\appdata\local\programs\python\python37\lib\site-packages\joblib\numpy_pickle.py", line 575, in load
    obj = _unpickle(fobj)
File "c:\users\chintan\appdata\local\programs\python\python37\lib\site-packages\joblib\numpy_pickle.py", line 504, in _unpickle
    obj = unpickler.load()
File "c:\users\chintan\appdata\local\programs\python\python37\lib\pickle.py", line 1088, in load
File "c:\users\chintan\appdata\local\programs\python\python37\lib\pickle.py", line 1376, in load_global
    klass = self.find_class(module, name)
File "c:\users\chintan\appdata\local\programs\python\python37\lib\pickle.py", line 1426, in find_class
    __import__(module, level=0)

Hi @Ritvik07Mahajan, welcome to the Streamlit community!

Can you post a repo with your code so that we can take a look?


okay sir…

here is the github link:

Hi @Ritvik07Mahajan, thanks for sharing your code! :grinning:

It took me a while to figure out what may be causing the error. From the notebook in your repo, I see scikit-learn==0.24.1 is installed in a conda environment. You may be getting this error because you’re running the app outside of the conda environment where scikit-learn is installed. Could you try either:

  1. Running the app within the conda environment or
  2. Installing scikit-learn==0.24.1 globally

Hopefully, the error is caused by this environment mismatch and nothing more obscure. Let me know if any of the options :point_up: work or you need more help debugging.

Snehan :balloon:

1 Like

Maybe I’m wrong, but that’s how I see it:
You load a model or an object, which is unpacked with “unpickle”.
But nowhere in the App.py you import the associated modules from sklearn.
Your App.py therefore does not know the type of this loaded object.

@Franky1 I suspected exactly that initially as well :thinking: However, I was able to clone the repo and successfully run App.py as-is on my machine, without having to import sklearn or any of its estimators in the script.

Okay, I’ve learned something new. :wink:
I would not have thought that it would work.

1 Like