ImportError: No module named sklearn.feature_extraction.text

。_饼干妹妹 提交于 2019-12-01 17:15:17

问题


I use from python 2.7 and pacman package manager, and install sclearn with it. but when i have an 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?


回答1:


For python 2, you should be able to use this command to install using pacman:

pacman -S python2-scikit-learn

Make sure the package name has the number "2" in it.

As per scikit-learn's installation guide, another way to install it is using pip:

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




回答2:


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:

Step 1: Make sure apt-get is updated
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

Step 3: pip install Scikit Learn
pip install --user --install-option="--prefix=" -U scikit-learn

Hope this helps!




回答3:


  1. Install python 2.7 from python home page
    • I installed 2.7.14 (latest by 22/07/2018)
  2. PIP is by default available in C:\Python27\scripts Added these locations (C:\Python27\ & C:\Python27\scripts) to system path variable (Windows10 machine)
  3. Install scikit-learn package

    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

pip install numpy

pip install scipy

C:\Python27\Lib\site-packages\




回答4:


Use this command pip install -U scikit-learn



来源:https://stackoverflow.com/questions/24871047/importerror-no-module-named-sklearn-feature-extraction-text

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!