Setting up iPython Notebook on Mac OS X

*Woo hoo!* I have the iPython notebook up and running and it actually runs in Safari just fine. (I had Chrome open, but Safari was where the window opened.) I don’t know if the MacPorts version of iPython simply doesn’t know all the dependencies, but here is a complete list of what you will need to `port search` for and then `sudo port install`:

* `jinja2`, needed for the notebook
* `sphinx`, needed for nbconvert
* `zmq`, needed for IPython’s parallel computing features, qt console and notebook
* `pygments`, used by nbconvert and the Qt console for syntax highlighting
* `tornado`, needed by the web-based notebook
* `nose`, used by the test suite
* `readline` (probably already installed), needed for the terminal

And then, of course, you’ll also need to install `ipython`, if you haven’t already, and do the `ipython_select` thing mentioned in a previous post. (Click the ( and you’ll see it listed.

With all that done, all you need to do is enter:

ipython notebook –pylab=inline

And a tab should open in your open browser that will slowly begin to collect stuff from your iPython session.

Eh, what’s that MacPorts?

Note to self, run `port upgrade outdated` more often. If you run it every few months, that’s a lot of stuff that needs updating. Also, I got this note:

XeTeX is built without support for Apple Type Services for Unicode Imaging
(ATSUI) or Apple Advanced Typography (AAT). To enable it, build texlive-bin with
the +atsui variant. Note that this will force texlive and all of its
dependencies to be built 32-bit.

Reason #35 to Like MacPorts

So the essay that Jonathan Goodwin and I wrote together using LDA topic modeling to explore the intellectual history of folklore studies is about to head into the _Journal of American Folklore_’s workflow and that means it has to get converted from LaTeX to Word. The way that conversion apparently works is:

LaTeX > HTML > Word

Fortunately, [someone has written a command line tool][], `latex2html`, that does the heavy lifting. And, thank you computing gods wherever, and whoever, ye may be, the tool is already in MacPorts. MacPorts makes it easy to find this out:

% port search latex2html
latex2html @2008 (print)
Convert LaTeX into HTML.

All that means is this:

% sudo port install latex2html

A whole lot of scrolled text later ends with:

—> Installing latex2html @2008_3
—> Activating latex2html @2008_3
—> Cleaning latex2html
—> Updating database of binaries: 100.0%
—> Scanning binaries for linking errors: 100.0%
—> No broken files found.

How do we use this tool?

> At this point, you’re ready to convert your files from LaTeX to HTML, and then possibly to Word. To invoke latex2html, switch to the directory with your .tex file, and latex2html filename. In its default state, latex2html will produce HTML that is broken up into multiple pages, usually one per section / subsection, much like the latex2html home page is. If you want to import your document into Word, you may wish to suppress this tendency. To do so, use the following command:

latex2html -split 0 -info 0 -no_navigation filename

> `-split 0` will make the entire LaTeX file into a single HTML page, while `-info 0` will remove the information bar at the bottom of the page and `-no_navigation` will remove the navigational menus on the top on bottom. This should produce a vanilla HTML file that Microsoft Word can read fairly easily.

> One thing to beware at this point: … Word will link to image files instead of including them in the document, which will mean that things like your equations will drop out if you send someone the .doc file without sending the image files as well. To fix this … go to Edit->Links, selecting all of the links in the dialog box, and clicking “Break Link”. Once that is done, save the file and the images will now be embedded into the document itself, ready for sending off to someone else.

`UPDATE: I just ran this, and it worked fine. And it was very fast.`

[someone has written a command line tool]:

MacPorts Cheat Sheet

Note to self: Macports needs a cheat sheet for people like me who can’t remember options and arguments precisely because Macports does such a good job of staying out of the way as you work. This should be done in LaTeX and made available on GitHub.

Joy = MacPorts (Python + Numpy + Scipy + Matplotlib + NLTK)

This is the TL:DR version of my previous post.

After installing [MacPorts]( via the package installer, open a terminal session and enter the following:

% sudo port selfupdate
% sudo port install python27
% sudo port install py27-numpy
% sudo port install py27-scipy
% sudo port install py27-matplotlib
% sudo port install py27-nltk
% sudo port install python_select
% sudo port select –set python python27

By the way, once I did all this. I was able to run a Python script that relied on `matplotlib` to run. *Sweet.*

MacPorts: The Key to Python Happiness

For those who want the TL;DR version which gives you all the commands you need to copy and paste into a terminal window, then it’s all here.

To do some of the work I do, I needed to have a working version of Python that included the numpy, scipy, and matplotlib libraries. I could not, however, get all these pieces to come together using homebrew. After trying a number of approaches from a variety of sources, I turned to StackOverflow for help. I got a response from tiago, who noted that “Homebrew and pip are great for minimalistic, pure python packages. But they stumble spectacularly with scipy or packages that require external non-python packages.” His advice was to turn, again, to MacPorts. (My first step was to un-install homebrew. After that, it was time to crank up the MacPorts assembly.)

Installing MacPorts

First, before you do anything else, you’ll need to make sure that you have Xcode’s command line tools installed. Installation is now as easy as typing the following in a terminal window:

xcode-select --install

You’ll get a GUI dialogue box, agree to the EULA, and then installation will happen. (And I believe software update / the App store will track updates for you.)

Second, Download the Mac OS X Package pkg Installer and step through the GUI install.

MacPorts should, as part of the install process, run sudo port selfupdate -v but you can always run it again. You know, just to make yourself feel better.

Third, you’ll need to install a version of Python. In my case, I am building a setup around Python 2.7, and so I entered sudo port -v install python27. The -v option gives you a verbose description of what’s happening. Be prepared to watch a lot of stuff scroll by. (If you’d rather not see all that and having the machine quietly do its thing, you can leave the -v off. Good for you for having quiet confidence in your Mac.)

MacPorts gives you some nice functionality with its search feature, which you can use to find MacPort portfiles. In my case, I wanted to start with numpy and so I entered port search numpy and got the following:

py-imread @0.2.5 (python, graphics)
    Reads images into numpy arrays

py-numpy @1.6.2 (python, math)
    The core utilities for the scientific library scipy for Python

py24-numpy @1.6.2 (python, math)
    The core utilities for the scientific library scipy for Python

py25-numpy @1.6.2 (python, math)
    The core utilities for the scientific library scipy for Python

py25-symeig @1.4 (python, science)
    Symeig - Symmetrical eigenvalue routines for NumPy.

py26-imread @0.2.5 (python, graphics)
    Reads images into numpy arrays

py26-numpy @1.6.2 (python, math)
    The core utilities for the scientific library scipy for Python

py26-scikits-audiolab @0.11.0 (python, science, audio)
    Audiolab is a python toolbox to read/write audio files from numpy arrays

py27-imread @0.2.5 (python, graphics)
    Reads images into numpy arrays

py27-numpy @1.6.2 (python, math)
    The core utilities for the scientific library scipy for Python

py31-numpy @1.6.2 (python, math)
    The core utilities for the scientific library scipy for Python

py32-numpy @1.6.2 (python, math)
    The core utilities for the scientific library scipy for Python

py33-numpy @1.6.2 (python, math)
    The core utilities for the scientific library scipy for Python

Found 13 ports.`

That py27-numpy is the one I want, and so I entered sudo port install py27-numpy. More scrolling. Done. Repeat these steps for scipy and matplotlib and nltk.

Finally, a crucial step is to make it so that your setup turns to your nice custom install of Python and not the one that came with the system. I usually accomplish this by editing my .bash_profile, but this did not work for me. Luckily, MacPorts has the solution: sudo port install python_select. Once you’ve done this, enter sudo port select --set python python27 and you’re done.

MacPorts requires Xcode

It’s right there in the installation instructions, but somehow I managed to miss it. And that explains why I couldn’t get `git` properly installed and setup. Bit I do wish that `port` would tell you that at some point. After all, I can’t be the only idiot?

*Phew* A Google search for the *Error 77* code reveals that there are other idiots out there. One of my main goals in life has thus been achieved: I have learned that I am not alone.