MacPorts is a package management system for macOS that simplifies the installation of software.
It can be used to easily install scikit-learn on macOS systems where MacPorts is installed.
To install scikit-learn using MacPorts, run the following command in your terminal:
sudo port install py39-scikit-learn
After installation, you can import scikit-learn in a Python script or interactive shell and print out the version number to confirm the installation:
import sklearn
print(sklearn.__version__)
Running the example gives an output like:
1.5.0
The first code block shows the MacPorts command to install scikit-learn. The
py39-
prefix specifies the Python version MacPorts should use.The second code block imports the installed
sklearn
library and prints its version number usingsklearn.__version__
.This verifies that scikit-learn was properly installed via MacPorts and is available for use in your Python environment on macOS.