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 22 March 2010. 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 recommend using the Enthought Python Distribution for OS X.

(In past years we used the fink package manager to install Python and the packages we need. Unfortunately, the fink repositories and code base do not seem to be as well maintained as in the past. However, if you do want to go this route, you can refer to the previous year's fink installation page.)

Basic OS X Install:

What Went Where

Python

OS X 10.6.X (Snow Leopard) has Python versions 2.5 and 2.6 pre-installed (in /usr/bin/python).

EPD 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: 6.1-1 (32-bit)

Python 2.6.4 |EPD 6.1-1 (32-bit)| (r264:75706, Dec 11 2009, 10:58:54) 
[GCC 4.0.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.6 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.6.4 |EPD 6.1-1 (32-bit)| (r264:75706, Dec 11 2009, 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