7

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?

General Grievance
  • 4,555
  • 31
  • 31
  • 45
Vahid Kharazi
  • 5,723
  • 17
  • 60
  • 103

3 Answers3

13

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

Nadine
  • 1,620
  • 2
  • 15
  • 27
8

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
Jean-François Fabre
  • 137,073
  • 23
  • 153
  • 219
Morgan Linton
  • 141
  • 2
  • 6
4
  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\

Narsireddy
  • 368
  • 5
  • 10