
I ran into an “ImportError” message while running a simple K-nearest neighbors image classification. The following import code was giving me this particular error:
from sklearn.neighbors import KNeighborsClassifier
And the exact error it would immediately provide me
Traceback (most recent call last): File "knn.py", line 5, in <module>
from sklearn.neighbors import KNeighborsClassifierImportError: No module named sklearn.neighbors
My first thought was to check for compatibility issues regarding Apple’s new Silicon M1 chip. Sure enough, Scikit-Learn mentions this in their install documents called “Installing on Apple Silicon M1 hardware.”
The recently introduced
macos/arm64
platform (sometimes also known asmacos/aarch64
) requires the open source community to upgrade the build configuration and automation to properly support it.At the time of writing (January 2021), the only way to get a working installation of scikit-learn on this hardware is to install scikit-learn and its dependencies from the conda-forge distribution, for instance using the miniforge installers:
https://github.com/conda-forge/miniforge
The following issue tracks progress on making it possible to install scikit-learn from PyPI with pip:
After uninstalling and reinstalling using the following code, it seems to have done the trick!
conda install -c conda-forge scikit-learn