Install Scientific Python, iPython, NLTK and Notebook on a Macbook

Recently we needed to set up several Macbook systems for scientific Python. The excellent install post at Lowin Data Company is the latest successor to ‘This is the Green Room‘ for Mac Lion. This is our Mountain Lion 10.8.4 update to catch up changes while keeping it brief. Here we go:

Step 1

Confirm you have an Apple ID (required)
Open the App Store, find and install Xcode (free of charge)

Screen Shot 2013-07-29 at 4.56.18 PM

Step 2

Start XCode and bring up Preferences:
(NOTE: If Xcode asks to Update Devices immediately after start, accept this update)

Screen Shot 2013-07-29 at 5.03.59 PM

Step 3

Now install the Command Line Tools, top line of the panel:

Screen Shot 2013-07-29 at 4.55.40 PM

Step 4

Open Terminal app and run the following commands:

ruby -e "$(curl -fsSL"
echo "export PATH=/usr/local/bin:$PATH" | sed 's!:/usr/local/bin$!!gp'| cat >>  ~/.bash_profile
# homebrew is now installed, look to their website for more instructions
brew install python --with-brewed-openssl
# python is now installed with pip and Setuptools
. ~/.bash_profile
# everything is ready to go and environment is set, install the target programs
pip install virtualenv
pip install numpy
brew install gfortran
pip install scipy
brew install freetype
brew install libpng
pip install matplotlib
brew install libyaml
pip install pyyaml
pip install nltk

Step 5

Now run ipython to confirm NLTK is installed, and to download the NLTK corpus files:

In [1]: import nltk
In [2]:

(Search screen for a newly opened panel to download collections. Choose ‘all-corpora’ and click ‘Download’ – same for ‘book’ – this is a lengthy download, go get coffee)

To get back to the Python prompt, exit the download panel. And let’s test that NLTK is really installed:

In [3]: from nltk.corpus import brown
In [4]: brown.words()
Out[4]: ['The', 'Fulton', 'County', 'Grand', 'Jury', 'said', ...]

Step 6

Now install an optional but very useful tool, iPython Notebook, to record and share your work as convenient .pynb “Notebook” files.

pip install tornado
brew install zmq
pip install pyzmq
pip install pygments

Step 7

Let’s test to see the Notebook works. Look for a browser to start up with a Notebook web page served locally.
(NOTE: You will not be able to view this web page from another system. The iPython Notebook defaults to local access only, as it is not secure by default. Kinda weird if you ask me, as it would be great to share with collaborators.)

ipython notebook --plyab=inline


I hope I didn’t have a dependency already installed and forgot to list it. If you find something, say so and I’ll update this post.

Install Scientific Python, iPython, NLTK and Notebook on a Macbook

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 )

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