Python 导入错误:没有名为 sklearn.feature_extraction.text 的模块
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24871047/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ImportError: No module named sklearn.feature_extraction.text
提问by 2 8
I use from python 2.7
and pacman
package manager, and install sclearn with it.
but when i have an ImportError:
我使用 frompython 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
How i can fix this error?
我该如何解决这个错误?
采纳答案by Nadine
For python 2, you should be able to use this command to install using pacman:
对于 python 2,您应该能够使用此命令使用 pacman 进行安装:
pacman -S python2-scikit-learn
pacman -S python2-scikit-learn
Make sure the package name has the number "2" in it.
确保包名称中包含数字“2”。
As per scikit-learn's installation guide, another way to install it is using pip:
根据scikit-learn 的安装指南,另一种安装方法是使用 pip:
pip install --user --install-option="--prefix=" -U scikit-learn
pip install --user --install-option="--prefix="-U scikit-learn
回答by Morgan Linton
When installing on Ubuntu Linux you have to have to install dependencies first using apt-get, then use a pip install otherwise the normal pip install of scikit-learn won't work properly. See below:
在 Ubuntu Linux 上安装时,您必须首先使用 apt-get 安装依赖项,然后使用 pip install 否则 scikit-learn 的正常 pip 安装将无法正常工作。见下文:
Step 1: Make sure apt-get is updated
sudo apt-get update
第 1 步:确保 apt-get 已更新
sudo apt-get update
Step 2: Install dependencies
sudo apt-get install build-essential python-dev python-setuptools python-numpy python-scipy libatlas-dev libatlas3gf-base
第二步:安装依赖
sudo apt-get install build-essential python-dev python-setuptools python-numpy python-scipy libatlas-dev libatlas3gf-base
Step 3: pip install Scikit Learn
pip install --user --install-option="--prefix=" -U scikit-learn
第三步:pip install Scikit Learn
pip install --user --install-option="--prefix=" -U scikit-learn
Hope this helps!
希望这可以帮助!
回答by Keerti
Use this command pip install -U scikit-learn
使用这个命令 pip install -U scikit-learn
回答by Narsireddy
- Install python 2.7 from python home page
- I installed 2.7.14 (latest by 22/07/2018)
- PIP is by default available in C:\Python27\scripts Added these locations (C:\Python27\ & C:\Python27\scripts) to system path variable (Windows10 machine)
- Install scikit-learn package
pip install -U scikit-learn
- 从 python 主页安装 python 2.7
- 我安装了 2.7.14(最新的 22/07/2018)
- PIP 默认在 C:\Python27\scripts 中可用 将这些位置(C:\Python27\ & C:\Python27\scripts)添加到系统路径变量(Windows10 机器)
- 安装 scikit-learn 包
pip install -U scikit-learn
We can see the scikit learn package library at c:\python27\lib\site-packages C:\Python27\Lib\site-packages\sklearn 4. Install numpy and scipy as these 2 are prerequisites for scikit-learn
我们可以在 c:\python27\lib\site-packages C:\Python27\Lib\site-packages\sklearn 看到 scikit learn 包库 4. 安装 numpy 和 scipy 因为这两个是 scikit-learn 的先决条件
pip install numpy
pip install scipy
pip 安装 numpy
pip 安装 scipy
C:\Python27\Lib\site-packages\
C:\Python27\Lib\site-packages\