ImportError:没有名为 sklearn.feature_extraction.text 的模块
Posted
技术标签:
【中文标题】ImportError:没有名为 sklearn.feature_extraction.text 的模块【英文标题】:ImportError: No module named sklearn.feature_extraction.text 【发布时间】:2014-09-12 07:25:48 【问题描述】:我使用 python 2.7
和 pacman
包管理器,并使用它安装 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
我该如何解决这个错误?
【问题讨论】:
【参考方案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】:-
从 python 主页安装 python 2.7
我安装了 2.7.14(2018 年 7 月 22 日最新)
PIP 默认在 C:\Python27\scripts 中可用
将这些位置(C:\Python27\ & C:\Python27\scripts)添加到系统路径变量(Windows10 机器)
安装 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\
【讨论】:
以上是关于ImportError:没有名为 sklearn.feature_extraction.text 的模块的主要内容,如果未能解决你的问题,请参考以下文章
ImportError:没有名为“sklearn.__check_build._check_build”的模块
jupyter notebook 中没有名为 sklearn.model_selection 的模块
为啥 ImportError:没有名为 lightgbm 的模块