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:
Confirm you have an Apple ID (required)
Open the App Store, find and install Xcode (free of charge)
Start XCode and bring up Preferences:
(NOTE: If Xcode asks to Update Devices immediately after start, accept this update)
Now install the Command Line Tools, top line of the panel:
Open Terminal app and run the following commands:
ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)" 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
Now run ipython to confirm NLTK is installed, and to download the NLTK corpus files:
ipython In : import nltk In : nltk.download()
(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 : from nltk.corpus import brown In : brown.words() Out: ['The', 'Fulton', 'County', 'Grand', 'Jury', 'said', ...]
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
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.