ModuleNotFoundError:没有名为“sklearn.externals.six”的模块

Posted

技术标签:

【中文标题】ModuleNotFoundError:没有名为“sklearn.externals.six”的模块【英文标题】:ModuleNotFoundError: No module named 'sklearn.externals.six' 【发布时间】:2020-09-06 03:02:49 【问题描述】:

我不断收到错误

ModuleNotFoundError: No module named 'sklearn.externals.six'

运行以下代码时:

from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
import pandas as pd
import mglearn
import numpy as np
from IPython.display import display
import matplotlib as pl
import sklearn

iris_dataset = load_iris()
X_train, X_test, y_train, y_test = train_test_split(iris_dataset['data'], iris_dataset['target'], random_state=0)
iris_dataframe = pd.DataFrame(X_train, columns=iris_dataset.feature_names)
pd.plotting.scatter_matrix(iris_dataframe, c=y_train, figsize=(15, 15), marker='o', hist_kwds='bins':20, s=60, alpha=.8, cmap=mglearn.cm3)

是否有我尚未导入或安装的模块?

【问题讨论】:

我不熟悉这些包,但知道你安装了哪个版本的 sklearn 可能会很有用。 请更新您的帖子以包括 1) 完整的错误跟踪(错误究竟在哪里弹出?)ypur scikit-learn 版本 (sklearn.__version__) 相关:***.com/questions/61881987/… 【参考方案1】:

模块 sklearn.externals.six 在 0.23 版中被删除。 如果你想使用这个模块,你必须降级到 0.22 或更低版本。

【讨论】:

【参考方案2】:

它将在 pandas 0.22 模块中,因为在 version 升级后,它被删除了,即 sklearn.external.six 。 如果仍然感到困惑,您可以查看文档。

【讨论】:

【参考方案3】:

我只需执行以下命令即可运行您的代码:

C:\Windows\system32>pip install sklearn
Collecting sklearn
  Downloading https://files.pythonhosted.org/packages/1e/7a/dbb3be0ce9bd5c8b7e3d87328e79063f8b263b2b1bfa4774cb1147bfcd3f/sklearn-0.0.tar.gz
Collecting scikit-learn (from sklearn)
  Downloading https://files.pythonhosted.org/packages/7e/e5/888491b7e2c16718a68dfd8498325e8927003410b2d19ba255d8751338a5/scikit_learn-0.23.1-cp38-cp38-win_amd64.whl (6.8MB)
     |████████████████████████████████| 6.8MB 2.2MB/s
Collecting joblib>=0.11 (from scikit-learn->sklearn)
  Downloading https://files.pythonhosted.org/packages/b8/a6/d1a816b89aa1e9e96bcb298eb1ee1854f21662ebc6d55ffa3d7b3b50122b/joblib-0.15.1-py3-none-any.whl (298kB)
     |████████████████████████████████| 307kB 3.2MB/s
Collecting threadpoolctl>=2.0.0 (from scikit-learn->sklearn)
  Downloading https://files.pythonhosted.org/packages/db/09/cab2f398e28e9f183714afde872b2ce23629f5833e467b151f18e1e08908/threadpoolctl-2.0.0-py3-none-any.whl
Requirement already satisfied: numpy>=1.13.3 in c:\python38\lib\site-packages (from scikit-learn->sklearn) (1.18.4)
Collecting scipy>=0.19.1 (from scikit-learn->sklearn)
  Downloading https://files.pythonhosted.org/packages/f8/b9/98a75846fdda3756ce75705b518dde4c599ba419d11415ce3fe1ebc4a885/scipy-1.4.1-cp38-cp38-win_amd64.whl (31.0MB)
     |████████████████████████████████| 31.0MB 1.1MB/s
Installing collected packages: joblib, threadpoolctl, scipy, scikit-learn, sklearn
  Running setup.py install for sklearn ... done
Successfully installed joblib-0.15.1 scikit-learn-0.23.1 scipy-1.4.1 sklearn-0.0 threadpoolctl-2.0.0
WARNING: You are using pip version 19.2.3, however version 20.1.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

C:Windows\system32>pip install mglearn
Collecting mglearn
  Downloading https://files.pythonhosted.org/packages/65/38/8aced26fce0b2ae82c3c87cd3b6105f38ca6d9d51704ecc44aa54473e6b9/mglearn-0.1.9.tar.gz (540kB)
     |████████████████████████████████| 542kB 1.3MB/s
Requirement already satisfied: numpy in c:\python38\lib\site-packages (from mglearn) (1.18.4)
Requirement already satisfied: matplotlib in c:\python38\lib\site-packages (from mglearn) (3.2.1)
Requirement already satisfied: scikit-learn in c:\python38\lib\site-packages (from mglearn) (0.23.1)
Requirement already satisfied: pandas in c:\python38\lib\site-packages (from mglearn) (1.0.3)
Collecting pillow (from mglearn)
  Downloading https://files.pythonhosted.org/packages/91/9e/1b45eed618c35010d8cc3ba57f12baf09af37054665b7cdf79aafa93ed75/Pillow-7.1.2-cp38-cp38-win_amd64.whl (2.0MB)
     |████████████████████████████████| 2.0MB 2.2MB/s
Requirement already satisfied: cycler in c:\python38\lib\site-packages (from mglearn) (0.10.0)
Collecting imageio (from mglearn)
  Downloading https://files.pythonhosted.org/packages/4c/2b/9dd19644f871b10f7e32eb2dbd6b45149c350b4d5f2893e091b882e03ab7/imageio-2.8.0-py3-none-any.whl (3.3MB)
     |████████████████████████████████| 3.3MB 126kB/s
Requirement already satisfied: joblib in c:\python38\lib\site-packages (from mglearn) (0.15.1)
Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in c:\python38\lib\site-packages (from matplotlib->mglearn) (2.4.7)
Requirement already satisfied: kiwisolver>=1.0.1 in c:\python38\lib\site-packages (from matplotlib->mglearn) (1.2.0)
Requirement already satisfied: python-dateutil>=2.1 in c:\python38\lib\site-packages (from matplotlib->mglearn) (2.8.1)
Requirement already satisfied: scipy>=0.19.1 in c:\python38\lib\site-packages (from scikit-learn->mglearn) (1.4.1)
Requirement already satisfied: threadpoolctl>=2.0.0 in c:\python38\lib\site-packages (from scikit-learn->mglearn) (2.0.0)
Requirement already satisfied: pytz>=2017.2 in c:\python38\lib\site-packages (from pandas->mglearn) (2020.1)
Requirement already satisfied: six in c:\python38\lib\site-packages (from cycler->mglearn) (1.14.0)
Installing collected packages: pillow, imageio, mglearn
  Running setup.py install for mglearn ... done
Successfully installed imageio-2.8.0 mglearn-0.1.9 pillow-7.1.2
WARNING: You are using pip version 19.2.3, however version 20.1.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

请注意,我的系统上有这个版本的 Python:

C:\Windows\system32>python --version
Python 3.8.3

以下是我系统上的 sklearn 和 mglearn 版本:

C:\Windows\system32>pip list
...
mglearn           0.1.9
...
scikit-learn      0.23.1
...

【讨论】:

【参考方案4】:

降级您的 scikit-learn 版本:

在 jupyter 笔记本中:

!pip install --upgrade scikit-learn==0.20.3

在终端:

pip install --upgrade scikit-learn==0.20.3

之后,代码将识别sklearn.external.six 模块。

【讨论】:

【参考方案5】:

可以使用官方六包。 首先安装六个使用:pip install six 然后你导入模块。无需降级 scikit-learn。

【讨论】:

【参考方案6】:

我来晚了,但这是由于 mglearn 包(内部尝试导入六个)。

你必须有一个旧版本,因为他们发布在 github 上的版本没有这个问题。也许来自随书附送的 CD...

要解决此问题,请执行以下操作:pip install --upgrade mglearn

【讨论】:

【参考方案7】:

你可以使用类似下面的东西..

from six import StringIO

【讨论】:

【参考方案8】:

取决于您使用的 IDE,但如果它是 spyder,那么您必须使用以下代码将 spyder 内核添加到您的 python 安装中: pip install spyder-kernels

【讨论】:

【参考方案9】:

你可以试试这个:-

import six
import sys
sys.modules['sklearn.externals.six'] = six

它对我有用。

礼貌 - https://github.com/alkaline-ml/pmdarima/issues/355

【讨论】:

【参考方案10】:

ModuleNotFoundError:没有名为“sklearn.externals”的模块; 'sklearn' 不是一个包

我出现了这个错误并在这里尝试了所有方法。最终意识到我在目录中命名了一个文件“sklearn.py”...

【讨论】:

【参考方案11】:
pip install --upgrade scikit-learn==0.20.3

【讨论】:

您是说您必须回到几年前的版本才能解决问题?如果是这样,请解释为什么这会有所帮助。 这是this answer的副本

以上是关于ModuleNotFoundError:没有名为“sklearn.externals.six”的模块的主要内容,如果未能解决你的问题,请参考以下文章

ModuleNotFoundError:没有名为“dataviz”的模块

ModuleNotFoundError:没有名为“numpy”的模块

错误:ModuleNotFoundError:没有名为“图像”的模块

ModuleNotFoundError:没有名为“knox”的模块

ModuleNotFoundError:没有名为“memoize”的模块

ModuleNotFoundError:没有名为“pssh”的模块