conda update scikit-learn (also scipy and numpy)

23,415

Solution 1

It looks like the versions reported by conda do not match the versions you're importing when you run Python. This makes me think that you've installed these packages in multiple places, and have your $PYTHONPATH variable set so that Python is finding different installations (sometimes installing some toolkit will add this in your bash/sh startup script) Try running

$ echo $PYTHONPATH

If anything is shown here, find your startup script and comment that out. After making sure that $PYTHONPATH is empty, try the following:

$ conda update conda  # make sure package listing is up-to-date
$ conda remove numpy scipy scikit-learn
$ conda install scikit-learn

That has generally worked for me in the past.

Solution 2

Note: Don't use pip command if you are using Anaconda or Miniconda

I tried following commands:

!conda update conda 
!pip install -U scikit-learn

It will install the required packages also will show in the conda list but if you try to import that package it will not work.

On the website http://scikit-learn.org/stable/install.html it is mentioned as: Warning To upgrade or uninstall scikit-learn installed with Anaconda or conda you should not use the pip.

Following Worked for me for scikit-learn on Anaconda-Jupyter Notebook.

Upgrading my scikit-learn from 0.19.1 to 0.19.2 in anaconda installed on Ubuntu on Google VM instance:

Run the following commands in the terminal:

First, check existing available packages with versions by using:

conda list    

It will show different packages and their installed versions in the output. Here check for scikit-learn. e.g. for me, the output was:

scikit-learn              0.19.1           py36hedc7406_0  

Now I want to Upgrade to 0.19.2 July 2018 release i.e. latest available version.

conda config --append channels conda-forge
conda install scikit-learn=0.19.2

Now check the required version of the scikit-learn is installed correctly or not by using:

conda list 

For me the Output was:

scikit-learn              0.19.2          py36_blas_openblasha84fab4_201  [blas_openblas]  conda-forge
Share:
23,415
Blue482
Author by

Blue482

Updated on July 09, 2022

Comments

  • Blue482
    Blue482 almost 2 years

    I think I have made a mess using pip install when I am supposed to use conda. As a result I couldn't update the scikit-learn package to the latest version. I uninstalled scikit-learn with both conda and pip, and then installed again using conda but now I have issue import sklearn:

    Python 2.7.11 |Anaconda custom (x86_64)| (default, Dec  6 2015, 18:57:58) 
    [GCC 4.2.1 (Apple Inc. build 5577)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    Anaconda is brought to you by Continuum Analytics.
    Please check out: http://continuum.io/thanks and https://anaconda.org
    
    from sklearn import metrics
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/Users/bowang/anaconda/lib/python2.7/site-packages/sklearn/metrics/__init__.py", line 7, in <module>
        from .ranking import auc
    ImportError: No module named ranking 
    

    Also there seems to be confusions with which version of sklearn/numpy/scipy it actually uses:

    $ conda update scikit-learn
    Using Anaconda Cloud api site https://api.anaconda.org
    Fetching package metadata: ......
    Solving package specifications: .........
    
    # All requested packages already installed.
    # packages in environment at /Users/bowang/anaconda:
    #
    scikit-learn              0.15.2               np18py27_0    http://repo.continuum.io/pkgs/free/osx-64/scikit-learn-0.15.2-np18py27_0.tar.bz2
    
    $ conda update scipy
    Using Anaconda Cloud api site https://api.anaconda.org
    Fetching package metadata: ......
    Solving package specifications: .........
    
    # All requested packages already installed.
    # packages in environment at /Users/bowang/anaconda:
    #
    scipy                     0.14.0               np18py27_0    http://repo.continuum.io/pkgs/free/osx-64/scipy-0.14.0-np18py27_0.tar.bz2
    

    Above shows I still can't update to the latest versions but:

    $ python
    Python 2.7.11 |Anaconda custom (x86_64)| (default, Dec  6 2015, 18:57:58) 
    [GCC 4.2.1 (Apple Inc. build 5577)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    Anaconda is brought to you by Continuum Analytics.
    Please check out: http://continuum.io/thanks and https://anaconda.org
    >>> import scipy
    >>> scipy.__version__
    '0.17.0'
    >>> import numpy
    >>> numpy.__version__
    '1.11.0'
    >>> import sklearn
    >>> sklearn.__version__
    '0.17.1'
    

    Is there a way to clean up and resolve all the confusions here and allow me to update and thus use the latest versions of sklearn/numpy/scipy? Thanks!