The ‘sklearn’ PyPI package is deprecated, use ‘scikit-learn’

In this post:

Problem description:

Recently I tried to run on PyCharm 2024.3.1.1 (Community Edition) , Python 3.13 some stuff with datasets. Beginning of the code was like:
from sklearn import datasets
iris_ds = datasets.load_iris()
digits_ds=datasets.load_digits()
print(digits_ds.data)
#print(iris_ds.data)
#... other lines .....

The problem is that package sklearn is not recognized, I tried to add it to project in PyCharm and it fail, in error messages it advice to run pip, to bypass eventual GUI problems. Here is what happened further: 

1) Try first pip install from .venv scripts from PyCharm project

C:\Windows\System32>C:\Users\Stefan\PycharmProjects\Sklearn-dataset\.venv\Scripts\activate.bat
(.venv) C:\Windows\System32>pip install sklearn

Collecting sklearn
  Using cached sklearn-0.0.post12.tar.gz (2.6 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... error
  error: subprocess-exited-with-error

  × Getting requirements to build wheel did not run successfully.
   exit code: 1
  ╰─> [15 lines of output]
      The 'sklearn' PyPI package is deprecated, use 'scikit-learn'
      rather than 'sklearn' for pip commands.

      Here is how to fix this error in the main use cases:
      - use 'pip install scikit-learn' rather than 'pip install sklearn'
      - replace 'sklearn' by 'scikit-learn' in your pip requirements files
        (requirements.txt, setup.py, setup.cfg, Pipfile, etc ...)
      - if the 'sklearn' package is used by one of your dependencies,
        it would be great if you take some time to track which package uses
        'sklearn' instead of 'scikit-learn' and report it to their issue tracker
      - as a last resort, set the environment variable
        SKLEARN_ALLOW_DEPRECATED_SKLEARN_PACKAGE_INSTALL=True to avoid this error

      More information is available at
      https://github.com/scikit-learn/sklearn-pypi-package
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× Getting requirements to build wheel did not run successfully.
 exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.

[notice] A new release of pip is available: 23.2.1 -> 24.3.1
[notice] To update, run: python.exe -m pip install --upgrade pip

2) Upgrade pip from Python binaries.

We see notice that pip is 23.2.1. version and suggestion is to upgrade it to latest 24.3.1
Going to python binaries:

(.venv) C:\Windows\System32>cd C:\Program Files\Python313

(.venv) C:\Program Files\Python313>python.exe -m pip install --upgrade pip
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: pip in c:\program files\python313\lib\site-packages (24.3.1)

(.venv) C:\Program Files\Python313>

We find that already Python 3.13 binaries have pip 24.3.1, hence we deduce that pip used by PyCharm is 23.2.1 and it should be upgraded too.
We go back to .venv scripts and try to upgrade pip from there.

3) Upgrade pip from PyCharm .venv

(.venv) C:\Program Files\Python313>cd C:\Users\Stefan\PycharmProjects\Sklearn-dataset\.venv\Scripts

(.venv) C:\Users\Stefan\PycharmProjects\Sklearn-dataset\.venv\Scripts>dir p*
 Volume in drive C has no label.
 Volume Serial Number is 2CD9-ED78

 Directory of C:\Users\Stefan\PycharmProjects\Sklearn-dataset\.venv\Scripts
12/31/2024  03:33 PM           108,431 pip-3.13.exe
12/31/2024  03:33 PM           108,431 pip.exe
12/31/2024  03:33 PM           108,431 pip3.13.exe
12/31/2024  03:33 PM           108,431 pip3.exe
12/31/2024  03:33 PM                24 pydoc.bat
12/31/2024  03:33 PM           202,744 pyexpat.pyd
12/31/2024  03:33 PM           105,840 python.exe
12/31/2024  03:33 PM            72,560 python3.dll
12/31/2024  03:33 PM         6,093,816 python313.dll
12/31/2024  03:33 PM           104,304 pythonw.exe
              10 File(s)      7,013,012 bytes
               0 Dir(s)  189,810,143,232 bytes free

(.venv) C:\Users\Stefan\PycharmProjects\Sklearn-dataset\.venv\Scripts>python.exe -m pip install --upgrade pip
Requirement already satisfied: pip in c:\users\stefan\pycharmprojects\sklearn-dataset\.venv\lib\site-packages (23.2.1)
Collecting pip
  Obtaining dependency information for pip from https://files.pythonhosted.org/packages/ef/7d/500c9ad20238fcfcb4cb9243eede163594d7020ce87bd9610c9e02771876/pip-24.3.1-py3-none-any.whl.metadata
  Downloading pip-24.3.1-py3-none-any.whl.metadata (3.7 kB)
Downloading pip-24.3.1-py3-none-any.whl (1.8 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.8/1.8 MB 7.9 MB/s eta 0:00:00
Installing collected packages: pip
  Attempting uninstall: pip
    Found existing installation: pip 23.2.1
    Uninstalling pip-23.2.1:
      Successfully uninstalled pip-23.2.1
Successfully installed pip-24.3.1

4) Try again to install sklearn in PyCharm .venv

(.venv) C:\Users\Stefan\PycharmProjects\Sklearn-dataset\.venv\Scripts>pip install sklearn
> fail with the same “ The 'sklearn' PyPI package is deprecated, use 'scikit-learn'

5) Install scikit-learn in .venv

(.venv) C:\Users\Stefan\PycharmProjects\Sklearn-dataset\.venv\Scripts>pip install scikit-learn
Collecting scikit-learn
  Downloading scikit_learn-1.6.0-cp313-cp313-win_amd64.whl.metadata (15 kB)
Collecting numpy>=1.19.5 (from scikit-learn)
  Downloading numpy-2.2.1-cp313-cp313-win_amd64.whl.metadata (60 kB)
Collecting scipy>=1.6.0 (from scikit-learn)
  Downloading scipy-1.14.1-cp313-cp313-win_amd64.whl.metadata (60 kB)
Collecting joblib>=1.2.0 (from scikit-learn)
  Downloading joblib-1.4.2-py3-none-any.whl.metadata (5.4 kB)
Collecting threadpoolctl>=3.1.0 (from scikit-learn)
  Downloading threadpoolctl-3.5.0-py3-none-any.whl.metadata (13 kB)
Downloading scikit_learn-1.6.0-cp313-cp313-win_amd64.whl (11.1 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 11.1/11.1 MB 25.6 MB/s eta 0:00:00
Downloading joblib-1.4.2-py3-none-any.whl (301 kB)
Downloading numpy-2.2.1-cp313-cp313-win_amd64.whl (12.6 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 12.6/12.6 MB 46.7 MB/s eta 0:00:00
Downloading scipy-1.14.1-cp313-cp313-win_amd64.whl (44.5 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 44.5/44.5 MB 67.5 MB/s eta 0:00:00
Downloading threadpoolctl-3.5.0-py3-none-any.whl (18 kB)
Installing collected packages: threadpoolctl, numpy, joblib, scipy, scikit-learn
Successfully installed joblib-1.4.2 numpy-2.2.1 scikit-learn-1.6.0 scipy-1.14.1 threadpoolctl-3.5.0

6) Verify in PyCharn project

After 5 in PyCharm taskbar we will see messages like “There is Updating skeletons…..” once updating skeletons complete, it was possible to run proposed code:

from sklearn import datasets
iris_ds = datasets.load_iris()
digits_ds=datasets.load_digits()
print(digits_ds.data)
#print(iris_ds.data)
#... other lines .....

Please note that it was even not necessary to change anything in code!