I ran a python3 program and got error

Traceback (most recent call last):
File “main.py”, line 1, in
from sklearn.metrics.pairwise import pairwise_distances
ModuleNotFoundError: No module named ‘sklearn’

It clearly says sklearn module is not available and second point to consider is I am using python3 and I have pyhton2 as well on my devbox.

To sort it out, I simply installed this module for python3 and to install sklearn for python3 off-course I need to use pip3 as default pip belongs to python2

pip3 install sklearn
Collecting sklearn
  Using cached sklearn-0.0.tar.gz (1.1 kB)
Collecting scikit-learn
  Downloading scikit_learn-0.24.2-cp38-cp38-manylinux2010_x86_64.whl (24.9 MB)
     |████████████████████████████████| 24.9 MB 4.1 MB/s 
Collecting scipy>=0.19.1
  Downloading scipy-1.6.3-cp38-cp38-manylinux1_x86_64.whl (27.2 MB)
     |████████████████████████████████| 27.2 MB 19 kB/s 
Collecting numpy>=1.13.3
  Downloading numpy-1.20.3-cp38-cp38-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (15.4 MB)
     |████████████████████████████████| 15.4 MB 21 kB/s 
Collecting threadpoolctl>=2.0.0
  Downloading threadpoolctl-2.1.0-py3-none-any.whl (12 kB)
Collecting joblib>=0.11
  Downloading joblib-1.0.1-py3-none-any.whl (303 kB)
     |████████████████████████████████| 303 kB 4.9 MB/s 
Building wheels for collected packages: sklearn
  Building wheel for sklearn (setup.py) ... done
  Created wheel for sklearn: filename=sklearn-0.0-py2.py3-none-any.whl size=1315 sha256=80529ca153bffd657de5c6662ecd596e1b5b1e13c64ca3264c4bce74021a20be
  Stored in directory: /home/ashu/.cache/pip/wheels/22/0b/40/fd3f795caaa1fb4c6cb738bc1f56100be1e57da95849bfc897
Successfully built sklearn
Installing collected packages: numpy, scipy, threadpoolctl, joblib, scikit-learn, sklearn
Successfully installed joblib-1.0.1 numpy-1.20.3 scikit-learn-0.24.2 scipy-1.6.3 sklearn-0.0 threadpoolctl-2.1.0

Leave a Reply

Your email address will not be published. Required fields are marked *