ImportError: No module named sklearn.feature_extraction.text

Question:

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?

Asked By: Vahid Kharazi

||

Answers:

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

Answered By: Nadine

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
Answered By: Morgan Linton
  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:Python27scripts
    Added these locations (C:Python27 & C:Python27scripts) 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:python27libsite-packages
C:Python27Libsite-packagessklearn
4. Install numpy and scipy as these 2 are prerequisites for scikit-learn

pip install numpy

pip install scipy

C:Python27Libsite-packages

Answered By: Narsireddy
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.