'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 1:[1]

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.

Solution 2:[2]

These code also helped me:

from sklearn.linear_model import SGDRegressor model_SGDRegressor=SGDRegressor()

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 matq007
Solution 2 Shoh