Cannot install scikit-learn in Python 3.4 in Ubuntu 14.04

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
>>> 

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.