scikit-learn Installation Tutorial

By Victor Zhong

Virtualenv

We will start by first installing a python environment management system called virtualenv. We assume that pip, the package management system for python, is already installed.

pip install virtualenv

Next, we'll set up a new virualenv at your/path/to/virtual/env:

virtualenv your/path/to/virtual/env

To actually switch over our paths to this new environment, do:

source your/path/to/virtual/env/bin/activate

When you are done working with this environment, you can deactivate the environment via:

deactivate

Scikit Learn and dependencies

To install scikit-learn as well as its dependencies, do the following in your virtualenv:

pip install numpy

Before installing scipy, you may need to obtain a fortran compiler. For OSX, this is done via something like brew install gfortran.

pip install scipy
pip install matplotlib
pip install scikit-learn

Sharing Your Setup

Virtualenv allows you to drill down on the exact set of packages required. Pip allows you to easily list out the packages for installation. To share your setup with another, you can simply list out the packages required as follows:

requirements.txt:

Flask==0.10.1

Flask-FlatPages==0.5

Frozen-Flask==0.11

Jinja2==2.7.1

Markdown==2.3.1

MarkupSafe==0.18

PyYAML==3.10

Pygments==1.6

Werkzeug==0.9.3

itsdangerous==0.22

wsgiref==0.1.2

Flask-Misaka==0.2.0

The other party can simply set up a new clean virtualenv and do:

pip install -r requirements.txt

If at any time you'd like a list of what is currently installed in your python environment (eg. so that you can populate your requirements.txt), do:

pip freeze