Cannot install scikit-learn in Python 3.4 in Ubuntu 14.04
Solution 1
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
>>>
Solution 2
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.
Related videos on Youtube
andreSmol
I am interested in Python, Machine Learning, Natural Language Processing, AI
Updated on September 18, 2022Comments
-
andreSmol over 1 year
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
-
Chintan over 9 yearsProbably your question is answered here stackoverflow.com/questions/10763440/…
-
andreSmol over 9 yearsThanks 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.
-
Chintan over 9 yearsDid you try out the instructions from the answer by @akaIDIOT ? It tells you to install the Python 3 version of pip.
-
andreSmol over 9 yearsThanks, it was the solution that worked: install:easy_install3 pip and then use pip3.4 install scikit-learn
-
Sylvain Pineau over 9 yearsWelcome to Ask Ubuntu. Please, could you put some of your time to read What should I do when someone answers my question?
-