无法导入 sklearn

Cant import sklearn

skitlear 已安装,但是当我 运行 import sklearn 时出现错误:ModuleNotFoundError: No module named 'sklearn' 请看下面:

System:
    python: 3.8.8 (default, Apr 13 2021, 15:08:03) [MSC v.1916 64 bit (AMD64)]
executable: C:\Users826\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' 

根据 Laci 要求编辑

1.Output 对于 jupyter kernelspec list:

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

2.Kernel.json内容:

{
 "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 共 where python:

C:\Users\xxx\Anaconda3\python.exe
C:\Users\xxx\AppData\Local\Microsoft\WindowsApps\python.exe

转到 anaconda cmd 或 miniconda cmd 并输入这个

conda install -c anaconda scikit-learn

之后重启 spyder 或 pycharm

您的 jupyter 似乎使用了名为 tf_plates 的环境,但 scikit-learn 安装在 base 环境中。你可以

  1. 在此环境中安装scikit-learn:
conda install --name tf_plates scikit-learn
  1. 另一种选择是在 jupyter 中使用 base 环境:

在您的 kernel.json 文件中将 C:\Users\33826\Anaconda3\envs\tf_plates\python.exe 更改为 C:\Users\33826\Anaconda3\python.exe