If you’re unsure whether scikit-learn is installed in your Python environment, you can quickly check by attempting to import it in a Python script or by checking the version from the command line.
This procedure will work on Windows, macOS, and Linux. Note that scikit-learn requires Python to be installed. If Python is not installed, checking for scikit-learn is moot.
You can check the scikit-learn version from the command line:
python -c "import sklearn; print(sklearn.__version__)"
Alternatively, create a short Python script that imports sklearn and prints the version:
import sklearn
print(sklearn.__version__)
Running either of these will give an output like:
1.5.0
The command line check attempts to import sklearn and reports the version number if installed. If sklearn is not installed, it will raise an
ImportError
.Similarly, the Python script imports sklearn which will fail if it’s not installed, otherwise it will print the version number using
sklearn.__version__
.The printed version number confirms that scikit-learn is installed and indicates which version is currently available in your Python environment.