MacPorts: The Key to Python Happiness

To do some of the work I want to do, in terms of statistical analyses as well as in terms of visualization of some of those results, I would like to have a working version of Python which has at its beck and call the numpy, scipy, and matplotlib modules. 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.)

Then:

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.

Now 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.


Comments are disabled on this post


2 Comments

  1. [...] UPDATE: Skip homebrew for now. MacPorts has everything you need and makes it terribly easy and consistent. I’ve posted a complete run-down of the steps, and can guarantee the results, here: The Key to Python Happiness. [...]

  2. [...] Share johnlaudun.org       1 week [...]