Checking the installed version of scikit-learn is often necessary to ensure compatibility with your Python environment and other dependencies. This procedure works across Windows, macOS, and Linux.
To check the version of scikit-learn, simply import the sklearn
library and print the __version__
attribute:
import sklearn
print(sklearn.__version__)
Running the example gives an output like:
1.5.0
The code block imports the
sklearn
library, making it available for use in the script.It then prints the version number of the installed
sklearn
library using the__version__
attribute.This is a quick and reliable way to confirm that scikit-learn is properly installed and to check which version is currently being used in your Python environment.