Search code examples
pythonscikit-learnpicklepythonanywhere

Python Anywhere - No module named 'sklearn.linear_model._stochastic_gradient'


I want to use the pickle module and serialize the model learned on my computer:

pickle.dump(clf, open(os.path.join(dest, 'classifier.pkl'), 'wb'), protocol=4)

When I open it on my computer as well, everything works fine:

clf = pickle.load(open(os.path.join('pkl_objects', 'classifier.pkl'), 'rb'))

Unfortunately when I do the same on pythonanywhere.com I get the error:

ModuleNotFoundError: No module named 'sklearn.linear_model._stochastic_gradient'

I have the following versions scikit-learn:

  • on my computer: 0.23.2
  • pythonanywhere.com is 0.21.3

How to standardize it?  


Solution

  • You can create a requirement.txt file where you define all the necessary dependencies with versions. Or you can make a virtual environment like they have in the docs. Or you can try running pip install scikit-learn --upgrade.