SciPy “Getting Started” Doesn’t Work on the Mac–How I Fixed It

I installed Scientific Python on my Mac (Snow Leopard version 10.6.8) using MacPorts and tried to do the Getting Started tutorial that plots a fast Fourier transform. As is often the case, it didn’t work without some fiddling. Here are the snags I hit and how I worked around them.

ipython -pylab Switch is Deprecated

The single-dash -pylab command line switch for ipython is now deprecated. Use two dashes instead. Fortunately, this information is printed in an error message.

libedit is Misconfigured and the Color Prompt Renders as Garbage Characters

Something is messed up with libedit. Notice the error message below and the fact that the prompt appears as gibberish characters 34In[1;3[0;34][0^D.

> ipython --pylab
RuntimeWarning: Leopard libedit detected - readline will not be well behaved
including some crashes on tab completion, and incorrect history navigation.
It is highly recommended that you install readline, which is easy_installable with: 'easy_install readline'
Python 2.7.2 (default, Nov 21 2011, 15:04:09)
Type "copyright", "credits" or "license" for more information.

IPython 0.11 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

Welcome to pylab, a matplotlib-based Python environment [backend: agg].
For more information, type 'help(pylab)'.

Again, the error message tells you what to do. I wanted to stay consistent with how I install code on my machine, so I used MacPorts to get the updated libedit instad of easy install. The command I ran was:

sudo port install py27-readline

Note that you may have to explicitly specify the Python version number in the port name. Depending on how your system in configured, the py-readline package may apply to the wrong version of Python.

The matplotlib show Command Does Nothing

Once you’ve got ipython working, you cut-and-paste the commands from the web page. All the math seems to go okay, but the matplotlib show command does nothing. The graph is never drawn. The problem is that the default backend specified in the matplotlibrc file is Agg. The fix is to copy this file from the package install directory (run matplotlib.matplotlib_fname() in the interpreter) to ~/.matplotlib and change the backend value to MacOS.

After I had made these three changes, the Getting Started tutorial worked as advertised.

Update: December 4, 2012

I just went through this process on a new computer and things went much more smoothly.

Python 2.7 on Mac OS X 10.7.5.ipython installs the correct version of readline and prints color characters fine. The Macports matplolib package prints the following message when it’s done installing.

The default backend is the interactive Mac OS X backend. Different backends can be specified using the ~/.matplotlib/matplotlibrc file. More details regarding backends
can be found in the matplotlib FAQ:

I don’t have a ~/.matplotlib/matplotlibrc and the FAQ URL doesn’t exist, but no matter. When I walked through the Scipy tutorial it showed the graph on the screen without any additional fiddling on my part. What a difference a year makes, I guess.

This entry was posted in Those that have just broken the flower vase. Bookmark the permalink.

One Response to SciPy “Getting Started” Doesn’t Work on the Mac–How I Fixed It

  1. Gary Verhaegen says:

    On my computer at least, the backend value must be MacOSX instead of MacOS as specified here. Anyway, thanks a lot for this post, as it allowed me to figure this out.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s