Checking the installation location of scikit-learn can be useful for troubleshooting or confirming the correct version is being used in a Python environment.
The procedure uses Python’s built-in inspect
module and will work across Windows, macOS, and Linux platforms.
python -c "import inspect; import sklearn; print(inspect.getfile(sklearn))"
Alternatively:
import inspect
import sklearn
print(inspect.getfile(sklearn))
Running the example gives an output like:
/usr/local/lib/python3.12/site-packages/sklearn/__init__.py
The first code block shows a one-liner Python command that can be run in the terminal to print the location of the installed scikit-learn package.
The second code block breaks this down into a regular Python script, importing the necessary
inspect
andsklearn
modules.inspect.getfile(sklearn)
returns the path to thesklearn
package’s__init__.py
file, revealing where scikit-learn is installed in the current Python environment.