Installing scientific computing packages for Python in Mac OS X
There are several options for installation Python and related packages
in Mac OS X, two of which are described here. (A third option, not
described here, is to piggyback off the built-in version of Python
that exists in /usr/bin/python.)
For an overview see: github.
Option 1. Enthought Python bundle
Enthought, Inc. has made available the
Python Enthought Distribution,
which bundles the
Python interpreter (version 2.7.3) along with many useful packages for
scientific computing (and, fortunately, most of what we need for the
computational methods course).
Although you will not need everything provided in the Enthought
bundle, the one-stop shopping (almost) is useful and quick.
Download the package from the
download page, follow the installation instructions, and complain
(politely, of course) to Enthought if something goes awry.
The only thing missing from the Enthought distribution is
Visual. Unfortunately
Visual and Enthought do not play that well with one-another. Here
is a hack which makes things work:
-- stolen from (http://www.spacemig.com/2012/03/python-vpython-and-enthought/)
- Check to see if you have a Fortran compiler -- if not download and
install one -- this will be needed to fix a problem with numpy that
the VPython installer causes
- If you are using "Lion" or "Mountain Lion" you can get one
from Apple as part of the "command line tools" for "Xcode"
- Another place to get a fortran compiler is
http://r.research.att.com/tools/.
- Type the following
- cd /Library/Frameworks/Python.framework/Versions
- sudo ln -s 7.3 2.7
- You will need to type in your root password.
- Download and install VPython
- The VPython installer overwrites numpy with an earlier version.
To fix it type
- You will get a bunch of error messages. Just ignore them. It should
now work.
Let me know if you come up with a better approach (I am willing to bet that
instead of using easy_install
you could just reinstall enthought, but I haven't checked).
Another thing you might want to do is update IPython. Enthought has a command line tool for
doing this. Just type "enpkg ipython". Alternatively, download IPython, unpack
the archive, and from that directory type "python setup.py install --user" --
the user flag means that it will be set up in your directory rather than the root directory.
Consequently you will not need to enter your root password, and it
will not mess anything up.
Option 2: Fink
Installing useful third-party software under Mac OS X is greatly
simplified by Fink, a port
of the Debian Linux apt and dpkg systems for package management.
This option is useful if (a) you already have Fink running on your
Mac OS X system, or (b) you will want to install other, non-Python-related
packages that are also available through Fink.
Download Fink (from finkproject.org) and install it.
Optionally there is a separate program, called FinkCommander, that
provides a graphical interface to Fink, but it is easy enough to use
Fink from the command line.
Fink manages dependencies, and will prompt you to install
other packages if necessary. It installs everything it needs in
the directory /sw.
Fink packages
Some of the packages listed below are
classified by fink as "unstable". This does not make them unusable,
but reflects rather that they have been tested less than the stable
packages. Configure fink to "use unstable packages" so that these can
be located. This can also be done - after fink has been installed -
by editing the file /sw/etc/fink.conf and adding to the list of
allowed Trees the "unstable/main" tree, so that your Trees line looks
something like this:
Trees: local/main stable/main stable/crypto unstable/main
python27
The core python package: even though OS X comes with python
preinstalled, you'll want to install a python package in fink;
python27 is the most recent that works with Scipy. Subsequent to this, fink will install
all other python-related packages in /sw/lib/python27/site-packages.
scipy-py27
SciPy, which contains many useful algorithms for integrating
ODEs, optimizing functions, etc.
Note that the scipy.org web site contains information on building SciPy
under Mac OS X. The build via fink proposed here seems generally more
reliable and manages all the various dependencies that one would otherwise
need to worry about.
visual-py27
VPython or Visual Python, a 3D graphics environment
matplotlib-py27
Matplotlib, a MATLAB-inspired plotting package
pil-py27
Python Imaging Library (PIL), useful for creating and manipulating images.
ImageMagick
ImageMagick (fink package: imagemagick) provides utilities for
manipulating images. Currently we are
using the "display" utility to draw image files on the screen. The
ImageMagick display utility (and probably many other pieces of ImageMagick)
requires XWindows (e.g., Apple's X11, or Xfree86 under fink). Installing
Apple's X11 opens a world of functionality, but if you're reluctant to do so,
there is a workaround for displaying images. Apple's Preview application
will display image files; instead of calling "display filename" to use
ImageMagick's display, call "open /Applications/Preview.app filename" (even
if this is being done in a system call within python).