OS X: Installing Python and its scientific computing packages

OS X: Installing Python & its scientific computing packages

While the overall recommendations here will not change, the details will always be dated. These notes were updated 6 November 2012. If you're reading this much after these dates, you may encounter changes or, in fact, may benefit from more up-to-date procedures and packages.

An example of such changes is that I now recommend using the Enthought Python Distribution for OS X.

Basic OS X Install:

What Went Where

Python

OS X 10.7 and later have Python version 2.7 pre-installed (in /usr/bin/python). We won't use this version, as it does not have all of the packages that we need and, since the system uses this Python, we would not want to change it.

The EPD installer put another Python at the Framework location noted above.

Let's test the installation.

In a Terminal window, type

which python
You should see
/Library/Frameworks/Python.framework/Versions/Current/bin/python
If not, then try rehash and the which command again.

If this doesn't solve it, then open another terminal window and try again.

Run python:

python
You should see something like:
Enthought Python Distribution -- http://www.enthought.com
Version: 7.3-2 (32-bit)

Python 2.7.2 |EPD 3.3-2 (32-bit)| (r264:75706, Oct 11 2012, 10:58:54) 
[GCC 4.2.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
The important thing is that it says version 2.7 is running. Hit Ctrl-D to exit.

Developing Python

iPython is a very convenient shell in which to develop and run Python. Its manual is here.

Let's test it:

ipython
You should see something like
Enthought Python Distribution -- http://code.enthought.com

Python 2.7.2 |EPD 7.3-2 (32-bit)| (r264:75706, Oct 11 2012, 10:58:54) 
Type "copyright", "credits" or "license" for more information.

IPython 0.10 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object'. ?object also works, ?? prints more.

Python Scientific Computing

Let's briefly check to see if the packages we need are there.

Type in the following responses to the iPython prompts (In [...]:), hitting return at the end of each line:

In [1]: import scipy

In [2]: import numpy

In [3]: import matplotlib

In [4]: import Image

In [5]: import pyglet

In [6]: import enthought.mayavi

In [7]:
In each case, the package was found and a new prompt returned. So the EPD install worked.

Hit Ctrl-D to exit:

Do you really want to exit ([y]/n)? y