Installing scikit-learn
|
This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production. |
scikit-learn is distributed as binary wheels on PyPI and as packages on conda-forge, so on the common platforms installing it
takes one command and nothing is compiled. The project is called scikit-learn; the Python package you import is named
sklearn, and that is the only place the short name appears. This page explains the supported ways to install it, how to
check what you got, which Python and dependency versions are required, and what to do when something goes wrong. It
targets scikit-learn 1.9 (1.9.1, released in September 2026) together with NumPy 2.5 and
pandas 3.1, and was checked in October 2026. Examples target Python 3.13 or 3.14 and were run on Python 3.13. Every command that produces output was run with Python 3.13.18 and
scikit-learn 1.9.1 and the output shown is the real one, with machine-specific paths removed.
The installation of the libraries scikit-learn builds on is covered in NumPy installation and versions and pandas installation and versions. The general question of how to organise Python environments for data work is in Environment Setup, and virtual environments and packaging in general are explained in Virtual Environments and Packaging.
The recommended way: an isolated environment
The official instructions recommend (but do not require) installing scikit-learn into a virtual environment, so that it and its
dependencies do not interfere with other projects or with the packages managed by the operating system. On Linux the
documentation specifically discourages mixing pip packages with packages installed by the distribution manager (apt,
dnf, pacman). Activate the environment in every new terminal before running Python.
pip and venv
# macOS and Linux
python3 -m venv sklearn-env
source sklearn-env/bin/activate
python -m pip install -U scikit-learn
# Windows (PowerShell or cmd)
python -m venv sklearn-env
sklearn-env\Scripts\activate
python -m pip install -U scikit-learn
python -m pip guarantees that pip belongs to the interpreter of the activated environment. Installing scikit-learn also
installs its required dependencies: NumPy, SciPy, joblib, threadpoolctl and narwhals.
conda
conda create -n sklearn-env -c conda-forge scikit-learn
conda activate sklearn-env
The conda-forge channel is community maintained and provides scikit-learn builds for Windows, macOS and Linux. The
conda-forge installers (Miniforge) do not need administrator permission. Using a single channel for every package of an
environment avoids the binary incompatibilities that mixing channels can cause.
Installing the usual companions
scikit-learn alone is enough to train models on NumPy arrays. A typical data science environment adds pandas for tables and Matplotlib for the plotting helpers (see the optional dependencies below):
python -m pip install -U scikit-learn pandas matplotlib
To pin the version the pages of this section were written for:
python -m pip install "scikit-learn==1.9.*"
Verifying the installation
The documentation suggests asking the package manager what it installed and then asking Python itself:
python -m pip show scikit-learn # version and location
python -m pip freeze # every package in the environment
python -c "import sklearn; sklearn.show_versions()"
With conda, replace the first two commands with conda list scikit-learn and conda list. On Linux with a system Python,
use python3 instead of python.
sklearn.show_versions() prints the information to paste into a bug report: operating system, Python version, the
versions of the dependencies that matter, whether scikit-learn was built with OpenMP and the thread-pool libraries it
found. This is the output on the machine used to check this page (long paths shortened):
import sys
import sklearn
print(sys.version_info[:3])
print(sklearn.__version__)
sklearn.show_versions()
(3, 13, 18)
1.9.1
System:
python: 3.13.18 (main, Oct 26 2026, 13:59:02) [Clang 23.1.3 ]
executable: .../sklearn-env/bin/python
machine: macOS-27.0.1-arm64-arm-64bit-Mach-O
Python dependencies:
sklearn: 1.9.1
pip: 26.2.2
setuptools: 84.2.1
numpy: 2.5.4
scipy: 1.18.1
Cython: 3.3.0
pandas: 3.1.0
matplotlib: 3.11.2
joblib: 1.6.0
threadpoolctl: 3.7.0
narwhals: 2.28.0
Built with OpenMP: True
threadpoolctl info:
user_api: openmp
internal_api: openmp
num_threads: 10
prefix: libomp
filepath: .../sklearn/.dylibs/libomp.dylib
version: None
A package installed from a wheel reports the exact release in sklearn.__version__. A development build reports a
.dev0 suffix, for example 1.10.dev0, which is the upcoming 1.10 series and not a release.
Python and dependency requirements
scikit-learn 1.9 requires Python 3.11 or newer (the minimum was raised to 3.11 in 1.8; scikit-learn 1.7 still accepted Python 3.10). The installed package declares its requirements in its metadata, which you can read back:
from importlib.metadata import requires, metadata
print(metadata("scikit-learn")["Requires-Python"])
print(requires("scikit-learn"))
>=3.11 ['numpy>=1.24.1', 'scipy>=1.10.0', 'joblib>=1.4.0', 'narwhals>=2.0.1', 'threadpoolctl>=3.5.0']
| Package | Minimum | Role |
|---|---|---|
NumPy |
1.24.1 |
arrays, the data model of every estimator |
SciPy |
1.10.0 |
sparse matrices, optimisation, statistics |
joblib |
1.4.0 |
parallelism ( |
threadpoolctl |
3.5.0 |
control of the BLAS and OpenMP thread pools |
narwhals |
2.0.1 |
data frame support (pandas, Polars); a required dependency since 1.9 |
These are minimums. A fresh pip install resolves to the newest compatible releases, which is why the environment above
contains NumPy 2.5.4 although scikit-learn only needs 1.24.1.
Optional dependencies are needed only for specific features:
| Package | Minimum | Needed for |
|---|---|---|
Matplotlib |
3.6.1 |
every |
pandas |
1.5.0 |
reading and returning data frames, |
Polars |
0.20.30 |
Polars input and output |
PyArrow |
13.0.0 |
Arrow-backed data frames in the project test suite |
rich |
14.1.0 |
the experimental progress-bar callback |
The minimum versions of the build-time and documentation tools (Cython, meson-python, Sphinx and so on) only matter when building from source and are listed in the official page.
The narwhals dependency is new in 1.9. It is a very small library that lets scikit-learn accept data frames from several
libraries and return them from set_output, replacing the data frame interchange protocol that Polars deprecated. If
you build an environment by hand from a very old lock file, expect it to appear as an extra package after upgrading.
Older versions and outdated statements
Instructions written for earlier releases often fail on current ones. The table summarises what changed.
| Older statement | Valid until | Today |
|---|---|---|
"Install Python 2.7 or 3.4" |
scikit-learn 0.20 was the last release supporting them (2018) |
Python 3.11 or newer is required |
|
removed in 0.23 |
|
|
the PyPI name |
|
"Install NumPy and SciPy first, then scikit-learn" |
source builds |
wheels pull their dependencies automatically |
The same applies to code: modules such as sklearn.cross_validation, sklearn.grid_search and sklearn.learning_curve
were replaced by sklearn.model_selection in 0.18, and preprocessing.Imputer by impute.SimpleImputer in 0.20.
Getting Started uses only the current names.
Configuration after installing
Installing is also the point where it is useful to know the global configuration, because it is visible through the
same module. sklearn.get_config() returns the current settings, sklearn.set_config() changes them for the whole
process and sklearn.config_context() changes them temporarily:
import sklearn
print(sklearn.get_config())
with sklearn.config_context(assume_finite=True):
print(sklearn.get_config()["assume_finite"])
print(sklearn.get_config()["assume_finite"])
{'assume_finite': False, 'working_memory': 1024, 'print_changed_only': True, 'display': 'diagram', 'pairwise_dist_chunk_size': 256, 'enable_cython_pairwise_dist': True, 'array_api_dispatch': False, 'transform_output': 'default', 'enable_metadata_routing': False, 'skip_parameter_validation': False, 'sparse_interface': 'spmatrix'}
True
False
Two entries are worth noting for 1.9. transform_output selects the default output container of transformers (see
The Estimator API), and sparse_interface is new in 1.9: it defaults to
"spmatrix" (SciPy sparse matrices) and can be set to "sparray" to receive SciPy sparse arrays instead; the
documentation announces that the default will switch to sparse arrays in a few releases. assume_finite=True skips the
check for NaN and infinity and is a performance setting to use with care.
Free-threaded Python
scikit-learn 1.6 introduced preliminary support for free-threaded CPython (the build without the Global Interpreter Lock), with wheels for the free-threaded Python 3.13 on all supported platforms. scikit-learn 1.8 added free-threaded wheels for Python 3.14, and its release notes recommend 3.14 over 3.13 for experiments because it fixed a number of issues. The standard installation commands work unchanged inside a free-threaded interpreter. The official installation page does not mention free-threaded builds; report problems with them to the project.
Nightly builds
Wheels for the development branch (the upcoming release, currently 1.10.dev0) are built every day on the newest Python version. They contain features that are merged but not released, and may change or break. They are useful to test whether your code survives the next release:
python -m pip install --pre --extra-index https://pypi.anaconda.org/scientific-python-nightly-wheels/simple scikit-learn
Uninstall the released package first if the installer keeps it. Do not use nightly wheels in production environments.
Distribution packages and other builds
Operating systems and Python distributions package scikit-learn too. These versions follow the distribution release
cycle and can be much older than the current release, so check sklearn.__version__ before following current
documentation.
| Platform | Command |
|---|---|
Alpine Linux |
|
Arch Linux |
|
Debian and Ubuntu |
|
Fedora |
|
MacPorts |
|
Anaconda |
included in the Anaconda distribution |
Intel Extension for Scikit-learn |
|
Intel Extension for Scikit-learn provides optimised implementations of selected estimators for x86_64 processors. They are
not enabled by default and are imported explicitly, for example from sklearnex.neighbors import NearestNeighbors. It is a
separate project, not part of scikit-learn.
Building from source is only needed to contribute to scikit-learn; it requires a compiler and the build tools listed in the official page and is not covered here.
Troubleshooting
-
Source build instead of a wheel. When
pipcannot find a wheel for your platform (an unusual processor, a very new Python version that has no wheels yet) it tries to compile NumPy, SciPy or scikit-learn, which is slow and needs a compiler. Check that the Python version is supported, upgradepip, and prefer conda-forge if wheels are missing. -
Windows path length.
pipcan fail withOSError: [Errno 2] No such file or directorywhen Python lives in a deeply nested folder such as underAppData. Enable long paths (setLongPathsEnabledto1underHKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystemwithregedit) and reinstall withpip install --exists-action=i scikit-learn. -
Import works in one place only. The interpreter that runs your notebook or IDE is often not the one where you installed the package. Print
sys.executableandsklearn.__file__, and install withpython -m pipfrom that interpreter. -
Plotting errors. Functions and
*Displayclasses that draw need Matplotlib; install it separately. -
A model loads on one machine and fails on another. Pickled models are tied to the scikit-learn version that wrote them; see the persistence page of this section before upgrading.
Report problems that these checks do not explain on the bug tracker of the project, including the output of show_versions().