1

skitlear is installed, however whe I run import sklearn i get an error: ModuleNotFoundError: No module named 'sklearn' please see bellow:

System:
    python: 3.8.8 (default, Apr 13 2021, 15:08:03) [MSC v.1916 64 bit (AMD64)]
executable: C:\Users\33826\Anaconda3\python.exe
   machine: Windows-10-10.0.19041-SP0

Python dependencies:
          pip: 21.2.2
   setuptools: 58.0.4
      sklearn: 1.0.2
        numpy: 1.21.5
        scipy: 1.4.1
       Cython: None
       pandas: 1.4.1
   matplotlib: 3.5.0
       joblib: 1.1.0
threadpoolctl: 2.2.0

Built with OpenMP: True
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_21264/3775665260.py in <module>
      1 get_ipython().system('python -c "import sklearn; sklearn.show_versions()')
----> 2 import sklearn

ModuleNotFoundError: No module named 'sklearn' 

EDITED as per Laci request

1.Output for jupyter kernelspec list:

Available kernels:
  python3    C:\Users\xxx\AppData\Roaming\jupyter\kernels\python3

2.Kernel.json content:

{
 "argv": [
  "C:\\Users\\33826\\Anaconda3\\envs\\tf_plates\\python.exe",
  "-m",
  "ipykernel_launcher",
  "-f",
  "{connection_file}"
 ],
 "display_name": "Python 3 (ipykernel)",
 "language": "python",
 "metadata": {
  "debugger": true
 }
}

3.Output of where python:

C:\Users\xxx\Anaconda3\python.exe
C:\Users\xxx\AppData\Local\Microsoft\WindowsApps\python.exe
Tadas
  • 39
  • 1
  • 1
  • 5
  • It seems that in the fist line `sklearn` works fine, but not in the second line. Do you have more kernels installed? If so, try to change it in jupyter notebook. – Laci Feb 18 '22 at 15:13
  • what do you mean by "more kernels installed"? how would I check that? and how to change it if so? – Tadas Feb 19 '22 at 07:14
  • https://stackoverflow.com/questions/28831854/how-do-i-add-python3-kernel-to-jupyter-ipython, https://queirozf.com/entries/jupyter-kernels-how-to-add-change-remove, https://support.tibco.com/s/article/How-to-change-the-kernel-version-in-Jupyter-Python-Notebooks – Laci Feb 19 '22 at 08:06
  • If you cannot fix the problem, edit your post and show us the following: 1) result of `jupyter kernelspec list` command - it shows folder location of your kernels 2) In that(those) folder(s), open up file(s) kernel.json and show them to us. 3) result of `where python` command at command prompt. – Laci Feb 19 '22 at 08:35
  • @Laci Edited as per your comment – Tadas Feb 19 '22 at 10:07

2 Answers2

0

Go to anaconda cmd or miniconda cmd and put this

conda install -c anaconda scikit-learn

after that restart spyder or pycharm

suhaib
  • 1
0

It seems that your jupyter uses an environment called tf_plates, but scikit-learn is installed in the base environment. You can

  1. Install scikit-learn in this environment:
conda install --name tf_plates scikit-learn
  1. Other alternative is to use the base environment in jupyter:

In your kernel.json file change C:\\Users\\33826\\Anaconda3\\envs\\tf_plates\\python.exe to C:\\Users\\33826\\Anaconda3\\python.exe

Laci
  • 2,738
  • 1
  • 13
  • 22