0

On the server of my firm I tried to run a Python script. Yet it told me that sklearn was missing but it is up-to-date in /usr/local/lib/python2.7/dist-packages

:~/Eclipse-Stats$ python Main.py
2017-07-24 14:01:55.852751
Traceback (most recent call last):
  File "Main.py", line 2, in <module>
    import kmeans
  File "/home/ubuntu/Eclipse-Stats/kmeans.py", line 3, in <module>
    import sklearn
ImportError: No module named sklearn
:~/Eclipse-Stats$ pip install -U scikit-learn
Requirement already up-to-date: scikit-learn in /usr/local/lib/python2.7/dist-packages

Maybe it thinks it isn't on the server but when I try to install it, it installs it on my laptop which already have it ?

I have Python 2.7.13 installed on the server. It seems it is the problem as far as when I run wiyt python3 it seems to work :

 ~/Eclipse-Stats$ python3 Main.py
  File "Main.py", line 113
    print "list of groups you can recommend : "
                                              ^
SyntaxError: Missing parentheses in call to 'print'

From Python interpreter

But a Python Specialist on the Spanish version of the site (FJSevilla) told me it wasn't sure.

I tried to import it from the python interpreter :

>>> import sklearn
Traceback (most recent call last):
File "<stdin>", line 1, in <module>

ImportError: No module named sklearn

So I tried to uninstall, purge and reinstall it (I don't remeber where but I think on the prompt):

Uninstall and reinstall

sudo apt-get install build-essential python-dev python-setuptools python-numpy python-scipy libatlas-dev libatlas3-base
...
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

Then I tried to import it again but it failed :

>>> import kmeans
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "kmeans.py", line 3, in <module>
    import sklearn
ImportError: No module named sklearn
>>> kmeans.__file__
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'kmeans' is not defined

And with :

>>>sudo pip install -U scikit-learn

>>> import sklearn
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named sklearn

A permission issue ?

My last attempts were to grant permissions issue according to this answer from boshea in 2013

ubuntu@ip-172-31-41-89:~/Eclipse-Stats$ sudo chmod -R go+rX /usr/local/lib/python2.7/dist-packages
ubuntu@ip-172-31-41-89:~/Eclipse-Stats$ python
Python 2.7.13 (default, Jul 24 2017, 09:52:34)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sklearn
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named sklearn

At the system level

FJSevilla proposed to do look if sklearn was already installed at the system level :

pip install --user --install-option="--prefix=" -U scikit-learn
/home/ubuntu/.local/lib/python2.7/site-packages/pip/commands/install.py:194: UserWarning: Disabling all use of wheels due to the use of --build-options / --global-options / --install-options.
  cmdoptions.check_install_build_global(options)
Requirement already up-to-date: scikit-learn in /usr/local/lib/python2.7/dist-packages

Anyway ...

$ ls /usr/local/lib/python2.7/dist-packages/sklearn
__check_build              exceptions.pyc            multiclass.py
__init__.py                externals                 multiclass.pyc
__init__.pyc               feature_extraction        multioutput.py
_build_utils               feature_selection         multioutput.pyc
_isotonic.so               gaussian_process          naive_bayes.py
base.py                    grid_search.py            naive_bayes.pyc
base.pyc                   grid_search.pyc           neighbors

It seems that the installation was okay but the interpreter doesn't look into the right folder ...

Antoine Coppin
  • 285
  • 2
  • 3
  • 12

0 Answers0