【问题标题】:ImportError: No module named sklearn.feature_extraction.textImportError:没有名为 sklearn.feature_extraction.text 的模块
【发布时间】:2014-09-12 07:25:48
【问题描述】:

我使用 python 2.7pacman 包管理器,并使用它安装 sclearn。 但是当我遇到 ImportError 时:

>>> from sklearn.feature_extraction.text import TfidfVectorizer
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named sklearn.feature_extraction.text

我该如何解决这个错误?

【问题讨论】:

    标签: python pacman


    【解决方案1】:

    对于 python 2,你应该可以使用 pacman 安装这个命令:

    pacman -S python2-scikit-learn

    确保包名中包含数字“2”。

    根据scikit-learn's installation guide,另一种安装方式是使用 pip:

    pip install --user --install-option="--prefix=" -U scikit-learn

    【讨论】:

      【解决方案2】:

      在 Ubuntu Linux 上安装时,您必须首先使用 apt-get 安装依赖项,然后使用 pip install 否则 scikit-learn 的正常 pip 安装将无法正常工作。见下文:

      第 1 步:确保 apt-get 已更新

      sudo apt-get update
      

      第 2 步:安装依赖项

      sudo apt-get install build-essential python-dev python-setuptools python-numpy python-scipy libatlas-dev libatlas3gf-base
      

      第 3 步:pip install Scikit Learn

      pip install --user --install-option="--prefix=" -U scikit-learn
      

      【讨论】:

        【解决方案3】:
        1. 从 python 主页安装 python 2.7
          • 我安装了 2.7.14(2018 年 7 月 22 日最新)
        2. PIP 默认在 C:\Python27\scripts 中可用 将这些位置(C:\Python27\ & C:\Python27\scripts)添加到系统路径变量(Windows10 机器)
        3. 安装 scikit-learn 包

          pip install -U scikit-learn

        我们可以在 c:\python27\lib\site-packages 看到 scikit learn 包库 C:\Python27\Lib\site-packages\sklearn 4. 安装 numpy 和 scipy,因为这两个是 scikit-learn 的先决条件

        pip 安装 numpy

        pip 安装 scipy

        C:\Python27\Lib\site-packages\

        【讨论】:

          猜你喜欢
          • 2013-03-11
          • 2012-12-07
          • 2012-05-23
          • 2019-07-29
          • 2015-07-04
          • 2014-03-15
          • 2017-12-29
          • 2017-05-09
          • 2013-06-04
          相关资源
          最近更新 更多