7

I am trying to get scikit-learn to Python 3.4 in Ubuntu 14.04. When a run the command:

sudo pip3 install -U scikit-learn

I get scikit-learn loaded into Python 2.7. I have also tried to use:

sudo pip3 install git+https://github.com/scikit-learn/scikit-learn.git

but I get only scikit-learn into Python 2.7. I am able load numpy and scipy into Python 3 using:

apt-get install python3-numpy python3-scipy

but python3-sklearn does not work.

I tried also to create a p3env but it did not work:

sudo virtualenv -p /usr/bin/python3 py3env
source py3env/bin/activate
(py3env)user:~$sudo pip install scikit-learn
Requiement already up-to-date:scikit-learn in /usr/local/lib/python2.7/dist-packages
5
  • Probably your question is answered here stackoverflow.com/questions/10763440/…
    – Chintan
    Oct 19, 2014 at 13:38
  • Thanks Chintan. I tried the recommendation in the link but it did not work for me. I updated my question with the virtual environment procedure but as you can see it did not work.
    – andreSmol
    Oct 19, 2014 at 14:39
  • Did you try out the instructions from the answer by @akaIDIOT ? It tells you to install the Python 3 version of pip.
    – Chintan
    Oct 19, 2014 at 14:40
  • Thanks, it was the solution that worked: install:easy_install3 pip and then use pip3.4 install scikit-learn
    – andreSmol
    Oct 19, 2014 at 14:55
  • Welcome to Ask Ubuntu. Please, could you put some of your time to read What should I do when someone answers my question? Oct 23, 2014 at 9:32

3 Answers 3

15

I successfully installed scikit-learn for python3 on 14.04 using the following steps:

  • sudo apt-get install build-essential python3-dev python3-setuptools python3-numpy python3-scipy python3-pip libatlas-dev libatlas3gf-base
  • sudo pip3 install scikit-learn

According to the official doc, make sure that ATLAS is used to provide the implementation of the BLAS and LAPACK linear algebra routines:

sudo update-alternatives --set libblas.so.3 \
    /usr/lib/atlas-base/atlas/libblas.so.3
sudo update-alternatives --set liblapack.so.3 \
    /usr/lib/atlas-base/atlas/liblapack.so.3

I can now use scikit-learn:

$ python3
Python 3.4.0 (default, Apr 11 2014, 13:05:11) 
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from sklearn import datasets
>>> 
0
1

In general, many Python packages that do not have explicit python3 implementations in the package manager (aka, python-numpy, python3-numpy) are Python3 compatible and can be installed by downloading the package and running:

python3 setup.py install

In other words, the setup script from python3.

Many of the packages that are not immediately compatible require only a handful of common changes, for example print/print(), xrange()/range(), range()/list(range()), zip()/list(zip()).

You can probably also use the standard install process and then copy the libraries from the python2x "dist-packages" folders to the python3x "dist-packages" folders, but that is a bit sloppy.

0

I used the command

sudo apt-get install python3-sklearn python3-sklearn-lib python3-sklearn-doc

to install scikit-learn to use Python 3.6 on Ubuntu 18.04.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .