Install NumPy, SciPy, scikit-learn on Mac OS X for data miners

Add on and summarized from blog http://penandpants.com/2012/02/24/install-python/

Outline: 1. install Xcode –> 2. install pip –> 3. install brew –> 4. install NumPy –> 5. install gfortran (important!) –> 6. install SciPy –> 7. install matplotlib (useful) –> 8. install scikit-learn –> 9. test

Preamble: Python 2.5 ~ above is preinstalled in the current Mac OS lion. To make sure, in terminal (search in spotlight), type python after $, you should be able to see the python version installed and prompted to the python interpretation environment. Else type “sudo easy_install python” to intall python2.

1. Download Xcode from app store and install it. After that, open installed Xcode, go to Preferences –>   Download–> Command Line Tools, click ‘install’ to install the commands which are not installed in the shell.

2. The following steps will all be done in terminal.  For this step, sudo easy_install pip.

3.

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
(updated according to source: http://brew.sh/)

export PATH=/usr/local/bin:/usr/local/share/python:$PATH

4. sudo pip install numpy

5. brew install gfortran  –> this is a critical step before installing scipy, as many dependencies of the latter is contained in this package

6. sudo pip install scipy

7. sudo pip install matplotlib

8. sudo pip install scikit-learn

9. launch python and test the installed packages.

(after $) python –>

(after >>>)

import numpy

import scipy

import matplotlib

import sklearn

Successfully installed all the packages if no error found after the import!

In addition, pandas can also be a handy library for data analysis, to install:

sudo pip install pandas

END

10 thoughts on “Install NumPy, SciPy, scikit-learn on Mac OS X for data miners

  • Thanks for writing this!
    A few notes:

    You should use pre tags when putting code into html. When I copied the ruby command, the curly-quotes came with it, instead of the normal double-quotes that bash understands.

    Secondly, pip shouldn’t really be run as sudo. For packages with lots of dependencies like this, it’s best to use a virtualenv, and do a pip install while in there.

  • Kevin is absolutely right. I tried the approach he suggested of using virtualenv and it works elegantly. No need for sudo with pip. Thanks to both of you <3

  • Thanks for this. I was finally able to install scikit-learn following your guideline after having spent hours scouring the web for a workable guide. In addition, I had some issues installing matplotlib. At first, I was getting an error with missing ‘freetype’. After I dealt with the linking issues, I got another set of errors which I finally resolved by deleting the old numpy installation, reinstalling numpy and then installing matplotlib.

  • Hi guys, when I’m trying to install the scikit.learn I have errors… the first is this:
    clang: error: unknown argument: ‘-mno-fused-madd’ [-Wunused-command-line-argument-hard-error-in-future]

    Any idea?

  • i have a problem with updating the scikit-learn using pip. I had to preempt the download of the scikit package and i know that the package is not is not successfully downloaded, but it shows that the requirement is satisfied once i try to reinstall the package.I couldn’t update it either. Any help!!

  • Perfect! Thank you.

    One note. gfortran is now part of gcc, so instead of….

    `5. brew install gfortran –> this is a critical step before installing scipy, as many dependencies of the latter is contained in this package`

    it’s now…

    `5. brew install gcc –> this is a critical step before installing scipy, as many dependencies of the latter is contained in this package`

    Note that this step takes a long time 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *