Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 583
Savvas Kourtis Avatar asked Jan 29 '20 19:01

Savvas Kourtis


People also ask

How do I install an older version of a python package?

How do I Install a Specific Version of a Python Package? To install a specific version of a Python package you can use pip: pip install YourPackage==YourVersion . For example, if you want to install an older version of Pandas you can do as follows: pip install pandas==1.1. 3 .

Should I install sklearn or scikit-learn?

In general, you are advised to install the library using the scikit-learn identifier (i.e. pip install scikit-learn ) but in your source code, you must import it using the sklearn identifier (i.e. import sklearn ).

Is sklearn same as scikit-learn?

Scikit-learn is also known as sklearn. It's a free and the most useful machine learning library for Python.


2 Answers

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
like image 167
FlyingTeller Avatar answered Oct 27 '22 23:10

FlyingTeller


I have a guess about what it's happening and I think you will find you answear here:

First let's check the python version installed within your system:

python --version                                                                                                                                                                              

> Python 3.8.0

If you're ready set and updated this should be your current python version, and I guess here lies the problem. You can check sickit-learn versions from its official pypi distribution page here. If you check the docs you will see that the package was meant to 2.7 or 3.5 python distributions.

So to run your code I guess the best way would be to use virtualenv or virtualenvwrapper (my personal choice) where you can create a clean env for your tests.

# On your terminal
# First let's check if python2 is installed

python2 --version                                                                                                                                                                             > Python 2.7.17

# and pip

python2 -m pip --version                                                                                                                                                                      
> pip 19.3 from /usr/lib/python2.7/site-packages/pip (python 2.7)

# Now create a virtual env using virtualenvwrapper and python2 as our main python

mkdir py2
mkvirtualenv -p python2 -a py2  py2 

# After that the python command will be binded to your python2 installation
python --version
> Python 2.7.17

# Now lets install sckit lib
python -m pip install scikit-learn==0.18

python -m pip freeze                                                                                                                                                                      
> DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
> scikit-learn==0.18

If everything is ok now you can run your code with no problems!

Remember!!!! Python 2 is deprecated and you should update your code to use a more recent python distribution.

Also, virtualenv is a good practice when working with python, if you don't know it take your time to set up!

like image 41
Pedro Frattezi Silva Avatar answered Oct 27 '22 22:10

Pedro Frattezi Silva