scikit-learn requires several dependencies, including NumPy, SciPy, joblib, and threadpoolctl.
These can all be easily installed along with scikit-learn using pip, the standard package installer for Python.
pip is included by default with Python 2 starting with version 2.7.9, and with Python 3 starting with version 3.4. This installation procedure will work on Windows, macOS, and Linux.
To install scikit-learn and its dependencies, simply run the following command in your terminal:
pip install -U numpy scipy scikit-learn joblib threadpoolctl
To confirm that the libraries were successfully installed, you can import them in a Python script or interactive shell and print out their version numbers:
import numpy
import scipy
import sklearn
import joblib
import threadpoolctl
print(f"numpy version: {numpy.__version__}")
print(f"scipy version: {scipy.__version__}")
print(f"scikit-learn version: {sklearn.__version__}")
print(f"joblib version: {joblib.__version__}")
print(f"threadpoolctl version: {threadpoolctl.__version__}")
Running the example gives an output like:
numpy version: 1.26.4
scipy version: 1.13.0
scikit-learn version: 1.5.0
joblib version: 1.4.0
threadpoolctl version: 3.4.0
The
pip
command installs NumPy, SciPy, scikit-learn, joblib, and threadpoolctl in a single line. The-U
flag specifies to upgrade the packages to the newest available versions.The Python code block imports each of the installed libraries and prints their version numbers using the
__version__
attribute.This verifies that all the required dependencies for scikit-learn were properly installed and are available for use in your Python environment.