Search code examples
pythonwindowsscikit-learnpipconda

Installing an old version of scikit-learn


Problem Statment

I'm trying to run some old python code that requires scikit-learn 18.0 but the current version I have installed is 0.22 and so I'm getting a warning/invalid data when I run the code.


What I've Tried

I tried installing the specific version both in the terminal: python -m pip install scikit-learn==0.18 and in conda and none of that has worked. All I can install is v 0.22. Help? Thanks.


Error In Terminal

ERROR: Failed building wheel for scikit-learn
Running setup.py clean for scikit-learn
Failed to build scikit-learn
Installing collected packages: scikit-learn
Found existing installation: scikit-learn 0.22.1
Uninstalling scikit-learn-0.22.1:
Successfully uninstalled scikit-learn-0.22.1
Running setup.py install for scikit-learn ... error
ERROR: Command errored out with exit status 1:

Error through conda environment:

PackagesNotFoundError: The following packages are not available from current channels:
- scikit-learn==0.18 this was after creating and activating the new environment


Solution

  • Tackling your issues one at a time:

    python -m pip install scikit-learn==0.18 fails

    This is probably due to the fact that scikit-learn==0.18, if you check on pypi only has whl files for python 3.5 and 2.7 for windows, therefore pip downloads the source distribution and then fails in compiling it, probably because it doesn't work with newer python versions

    The following packages are not available from current channels

    This happens, because scikit-learn==18.0 simply does not exist in the default conda channels. On my win64 machine, the oldesst version that I can install is 19.0 (You can check by typing conda search scikit-learn in the cmd), so unfortunately no way to install using the default conda channels. There is a channel called free (found through the anaconda website) that has scikit-learn 18.0, so you could install with:

    conda install -c free scikit-learn 
    

    To also make sure that the python version is compatible, I would just create a fitting environment:

    conda create -n py35 -c free scikit-learn=0.18.0