-1

I installed scikit-learn both using pip and conda commandas. Whenever I check the package, it shows that it is already installed but, whenever I try import it, it shows error.

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.model_selection import train_test_split
%matplotlib inline

ERROR:

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-33-82d3fc6531ea> in <module>
      3 import matplotlib.pyplot as plt
      4 import seaborn as sns
----> 5 from sklearn.model_selection import train_test_split
      6 get_ipython().run_line_magic('matplotlib', 'inline')

ModuleNotFoundError: No module named 'sklearn'

I have tried reinstalling it multiple times but it shows the same error

  • 1
    Please do `pip3 install --upgrade scikit-learn` and post your version of scikit-learn. – felice Nov 20 '19 at 05:15
  • are you using virtualenv? – Vikas Gautam Nov 20 '19 at 05:22
  • I just found out that scikit is not installed with pip3. Whenever I try to install it, the setup shows error and exits with exit status 1 –  Nov 20 '19 at 05:28
  • Possible duplicate of [ModuleNotFoundError: No module named 'sklearn'](https://stackoverflow.com/questions/46113732/modulenotfounderror-no-module-named-sklearn) – PV8 Nov 20 '19 at 08:24
  • here are some tips and advices: https://stackoverflow.com/questions/46113732/modulenotfounderror-no-module-named-sklearn/52521214 – PV8 Nov 20 '19 at 08:24

3 Answers3

0

Make sure that if you install the sklearn package in the python version that you are working. For suppose if your system has two versions of python installed in it like both python 2 and python 3 then you have installed sklearn package in python 2 and executing your code in python 3 or vice-versa.

0

I think you don't have latest version of sklearn because in old version of sklearn below code was not working.

from sklearn.model_selection import train_test_split

Please update your sklearn by following command

conda update scikit-learn
Vaibhav Mishra
  • 227
  • 2
  • 11
0

I got the same error while installing these. What you can do is install all the packages using the command

conda install pandas 

and all other packages similarly or all in once

conda install pandas numpy matplotlib scikit-learn

in your project directory.

And now you can open your jupyter notbook using command

jupyter notebook

in the same environment or I should say same project directory.