To install scikit-learn, run python -m pip install scikit-learn. You install it under that name but import it in Python as sklearn.
The install command
python -m pip install scikit-learn
On Windows, py -m pip install scikit-learn does the same. Using python -m pip ties pip to the interpreter that will run your script, which avoids the usual "installed but not found" mismatch. pip also pulls in the dependencies for you. PyPI lists NumPy, SciPy, joblib, threadpoolctl and narwhals as core dependencies of the current release, so you do not install those first.
To upgrade an existing install, add -U:
python -m pip install -U scikit-learn
Install it in a virtual environment
The official installation page recommends a virtual environment and describes it as optional but strongly recommended, to avoid conflicts with other packages. Its steps for Windows are:
python -m venv sklearn-env
sklearn-env\Scripts\activate
pip install -U scikit-learn
On macOS and Linux, the activation line changes (use python3 on Linux if python is not available):
python -m venv sklearn-env
source sklearn-env/bin/activate
pip install -U scikit-learn
The page adds a reminder that matters in practice: activate the environment in every new terminal session before running any Python command. If you open a new terminal and skip that step, you are back on the global interpreter, and import sklearn will fail there. For a fuller walkthrough of environments, see how to create and use a Python virtual environment.
Check that scikit-learn installed
The installation page lists three read-only checks:
python -m pip show scikit-learn
python -m pip freeze
python -c "import sklearn; sklearn.show_versions()"
The first prints the installed version and its location. The second lists every package in the environment. The third imports the module and prints version information for Python, the system and the dependencies. If the third command prints a table instead of a traceback, the install works for that interpreter.
To see it do something, run the fit-and-predict example from the scikit-learn Getting Started guide:
from sklearn.ensemble import RandomForestClassifier
clf = RandomForestClassifier(random_state=0)
X = [[1, 2, 3], # 2 samples, 3 features
[11, 12, 13]]
y = [0, 1] # classes of each sample
clf.fit(X, y)
print(clf.predict(X))
print(clf.predict([[4, 5, 6], [14, 15, 16]]))
Example output, matching the guide:
[0 1]
[0 1]
Here fit takes a samples matrix X of shape (n_samples, n_features) and the target values y. After fitting, the same object predicts classes for new data without retraining.
Python version requirements
As of November 2026, PyPI shows scikit-learn 1.9.1, released September 10, 2026, with Requires-Python >=3.11. The installation page also records that scikit-learn 1.7 required Python 3.10 or newer, so the floor rises over time. If your Python is older than the current release supports, pip does not fail loudly in every case: it can fall back to an older scikit-learn that still supports your interpreter. Run python -m pip show scikit-learn after installing and look at the version line to see what you actually got. If it is older than you expected, check python --version, and see how to install a specific package version if you need to pin one on purpose.
The 1.9.1 dependency minimums on PyPI are NumPy 1.24.1, SciPy 1.10.0, joblib 1.4.0 and threadpoolctl 3.5.0. Matplotlib 3.6.1 or newer is optional and only needed for plotting.
Optional extras: Matplotlib and pandas
A plain install is enough to train and evaluate models on arrays. The documentation says plotting helpers, such as functions starting with plot_ and classes ending with Display, need Matplotlib. Install it alongside if you want those:
python -m pip install scikit-learn matplotlib
PyPI lists pandas, seaborn, Plotly and scikit-image as optional dependencies used by some of the examples, not by the library itself. If you are loading tabular files, you will likely want pandas too. The related Excel setup is covered in pip install pandas openpyxl.
Other ways to install it
The installation page also documents conda, using the conda-forge channel:
conda create -n sklearn-env -c conda-forge scikit-learn
conda activate sklearn-env
Use one tool per environment. Mixing pip and conda installs of the same package in one environment is a common source of confusing breakage. The page also lists distribution packages for Debian and Ubuntu, Fedora, Arch and others, for example sudo apt-get install python3-sklearn python3-sklearn-lib python-sklearn-doc. On Linux it says that installing pip packages alongside packages managed by the distribution's package manager is discouraged, which is another reason to use a virtual environment there.
If you want the same install on another machine, record the version in a requirements file. The format is explained in pip install requirements.txt.
If it still fails
ModuleNotFoundError: No module named 'sklearn'. Either the install went to a different interpreter than the one running your script, or you tried to install a package namedsklearninstead ofscikit-learn. Install withpython -m pip install scikit-learnusing the samepythonthat runs the script, and activate your virtual environment first. More background is in the ModuleNotFoundError guide.error: externally-managed-environment. Your system Python blocks global pip installs. Create a virtual environment as shown above, then install inside it. See Fix pip "error: externally-managed-environment".- pip starts compiling NumPy or SciPy from source. The installation page says to make sure binary wheels are used and that NumPy and SciPy are not recompiled from source. Upgrade pip with
python -m pip install -U pipand check that your Python version is one the current release supports. - Path-length errors on Windows. The installation page recommends enabling long paths by setting the
LongPathsEnabledregistry value to 1, then runningpip install --exists-action=i scikit-learn. Changing the registry is a system setting, so read the page first and decide whether you want to do it. - A file named
sklearn.pyorscikit-learn.pyin your project. Python searches the script's folder first, so a file with the module's name shadows the real one. Rename it.
Frequently asked questions
- Why do I install scikit-learn but import sklearn?
- The package is distributed under the name scikit-learn, but the Python module inside it is called sklearn. The official installation page shows the check as python -c "import sklearn; sklearn.show_versions()" right after installing scikit-learn with pip.
- Which Python version does scikit-learn need?
- As of November 2026, PyPI lists scikit-learn 1.9.1 (released September 10, 2026) with Requires-Python >=3.11. Older scikit-learn releases accepted older Python versions, so if pip picks an old release for you, check python --version first.
- Do I need NumPy and SciPy installed first?
- No. pip installs them as dependencies. PyPI lists NumPy 1.24.1 or newer, SciPy 1.10.0 or newer, joblib, threadpoolctl and narwhals as core dependencies of 1.9.1.
- Is a virtual environment required?
- No, but the scikit-learn installation page says it is strongly recommended, to avoid conflicts with other packages. It also says to activate the environment in every new terminal session before running Python commands.
- Do I need Matplotlib?
- Only for plotting. The installation page says scikit-learn's plotting functions (those starting with plot_ and classes ending with Display) require Matplotlib, which is not needed for fitting and predicting.