Install the latest official release
. This
is the best approach for most users. It will provide a stable version
and pre-built packages are available for most platforms.
Install the version of scikit-learn provided by your
operating system or Python distribution
.
This is a quick option for those who have operating systems or Python
distributions that distribute scikit-learn.
It might not provide the latest release version.
Building the package from source
. This is best for users who want the
latest-and-greatest features and aren’t afraid of running
brand-new code. This is also needed for users who wish to contribute to the
project.
Operating System
Packager
Install the 64bit version of Python 3, for instance from
https://www.python.org
.
Install Python 3 using
homebrew
(
brew install python
) or by manually installing the package from
https://www.python.org
.
Install python3 and python3-pip using the package manager of the Linux Distribution.
Install conda using the
Anaconda or miniconda
installers or the
miniforge
installers
(no administrator permission required for any of those).
python3 -m pip show scikit-learn # to see which version and where scikit-learn is installedpython3 -m pip freeze # to see all packages installed in the active virtualenvpython3 -c "import sklearn; sklearn.show_versions()"
python -m pip show scikit-learn # to see which version and where scikit-learn is installedpython -m pip freeze # to see all packages installed in the active virtualenvpython -c "import sklearn; sklearn.show_versions()"
python -m pip show scikit-learn # to see which version and where scikit-learn is installedpython -m pip freeze # to see all packages installed in the active virtualenvpython -c "import sklearn; sklearn.show_versions()"
python -m pip show scikit-learn # to see which version and where scikit-learn is installedpython -m pip freeze # to see all packages installed in the active virtualenvpython -c "import sklearn; sklearn.show_versions()"
conda list scikit-learn # to see which scikit-learn version is installedconda list # to see all packages installed in the active conda environmentpython -c "import sklearn; sklearn.show_versions()"
Using such an isolated environment makes it possible to install a specific
version of scikit-learn with pip or conda and its dependencies independently of
any previously installed Python packages. In particular under Linux is it
discouraged to install pip packages alongside the packages managed by the
package manager of the distribution (apt, dnf, pacman…).
Note that you should always remember to activate the environment of your choice
prior to running any Python command whenever you start a new terminal session.
If you have not installed NumPy or SciPy yet, you can also install these using
conda or pip. When using pip, please ensure that
binary wheels
are used,
and NumPy and SciPy are not recompiled from source, which can happen when using
particular configurations of operating system and hardware (such as Linux on
a Raspberry Pi).
Scikit-learn plotting capabilities (i.e., functions start with “plot_”
and classes end with “Display”) require Matplotlib. The examples require
Matplotlib and some examples require scikit-image, pandas, or seaborn. The
minimum version of Scikit-learn dependencies are listed below along with its
purpose.
Dependency
Minimum Version
Purpose
numpy
1.19.5
build, install
scipy
1.6.0
build, install
joblib
1.2.0
install
threadpoolctl
2.0.0
install
cython
3.0.8
build
matplotlib
3.3.4
benchmark, docs, examples, tests
scikit-image
0.17.2
docs, examples, tests
pandas
1.1.5
benchmark, docs, examples, tests
seaborn
0.9.0
docs, examples
memory_profiler
0.57.0
benchmark, docs
pytest
7.1.2
tests
pytest-cov
2.9.0
tests
0.0.272
tests
black
23.3.0
tests
tests
pyamg
4.0.0
tests
polars
0.19.12
tests
pyarrow
12.0.0
tests
sphinx
6.0.0
sphinx-copybutton
0.5.2
sphinx-gallery
0.15.0
numpydoc
1.2.0
docs, tests
Pillow
7.1.2
pooch
1.6.0
docs, examples, tests
sphinx-prompt
1.3.0
sphinxext-opengraph
0.4.2
plotly
5.14.0
docs, examples
conda-lock
2.4.2
maintenance
Warning
Scikit-learn 0.20 was the last version to support Python 2.7 and Python 3.4.
Scikit-learn 0.21 supported Python 3.5-3.7.
Scikit-learn 0.22 supported Python 3.5-3.8.
Scikit-learn 0.23 - 0.24 require Python 3.6 or newer.
Scikit-learn 1.0 supported Python 3.7-3.10.
Scikit-learn 1.1 and later requires Python 3.8 or newer.
Some third-party distributions provide versions of
scikit-learn integrated with their package-management systems.
These can make installation and upgrading much easier for users since
the integration includes the ability to automatically install
dependencies (numpy, scipy) that scikit-learn requires.
The following is an incomplete list of OS and python distributions
that provide their own version of scikit-learn.
Alpine Linux’s package is provided through the
official repositories
as
py3-scikit-learn
for Python.
It can be installed by typing the following command:
Arch Linux’s package is provided through the
official repositories
as
python-scikit-learn
for Python.
It can be installed by typing the following command:
The Debian/Ubuntu package is split in three different packages called
python3-sklearn (python modules), python3-sklearn-lib (low-level
implementations and bindings), python3-sklearn-doc (documentation).
Note that scikit-learn requires Python 3, hence the need to use the python3-
suffixed package names.
Packages can be installed using apt-get:
The MacPorts package is named py<XY>-scikits-learn,
where XY denotes the Python version.
It can be installed by typing the following
command:
sudoportinstallpy39-scikit-learn
Anaconda and Enthought Deployment Manager for all supported platforms¶
Anaconda and
Enthought Deployment Manager
both ship with scikit-learn in addition to a large set of scientific
python library for Windows, Mac OSX and Linux.
Anaconda offers scikit-learn as part of its free distribution.
Intel maintains an optimized x86_64 package, available in PyPI (via pip),
and in the main, conda-forge and intel conda channels:
condainstallscikit-learn-intelex
This package has an Intel optimized version of many estimators. Whenever
an alternative implementation doesn’t exist, scikit-learn implementation
is used as a fallback. Those optimized solvers come from the oneDAL
C++ library and are optimized for the x86_64 architecture, and are
optimized for multi-core Intel CPUs.
Note that those solvers are not enabled by default, please refer to the
scikit-learn-intelex
documentation for more details on usage scenarios. Direct export example:
fromsklearnex.neighborsimportNearestNeighbors
Compatibility with the standard scikit-learn solvers is checked by running the
full scikit-learn test suite via automated continuous integration as reported
on https://github.com/intel/scikit-learn-intelex. If you observe any issue
with scikit-learn-intelex, please report the issue on their
issue tracker.
Error caused by file path length limit on Windows¶
It can happen that pip fails to install packages when reaching the default path
size limit of Windows if Python is installed in a nested location such as the
AppData folder structure under the user home directory, for instance: