Wednesday, February 13, 2013

Spyder and IPython in OS X Mountain Lion

These notes describe how to use homebrew and pip to get Spyder and IPython working in OS X Mountain Lion.  They are based in part on this blog post.

Note

Install XCode (from App Store) and Command Line Utilities for XCode (from Apple website after filling out a bunch of information) before proceeding. These packages install a bunch of compilers not included in OS X by default.

Brew

* Overview homebrew is a software management system for OS X built on Ruby and git that allows people to write install scripts for various packages that handle all required dependencies and compiler flags in a controlled manner. It is similar to MacPorts but seems to work a little better, possibly because its user base has more active contributors who keep its formulae up to date and working.
Warning: brew is kind of pushy about keeping it updated. Be careful about running brew upgrade. Don't do it just to keep up to date. Do it when you need new packages for specific features or to install other packages that depend on them. I have found that formulae are often updated without thorough testing so sometimes upgrades can break things. Consider looking at recently opened issues on the github pages of taps you will be upgrading from to see if there are any open issues that might affect the upgrade.
* Installation
ruby -e "$(curl -fsSkL raw.github.com/mxcl/homebrew/go)" then add to .bash_profile: export PATH=/usr/local/bin:$PATH

Python

brew install python --framework --universal then add to .bash_profile: export PATH=/usr/local/share/python:$PATH and change link to Python: cd /System/Library/Frameworks/Python.framework/Versions sudo rm Current ln -s /usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/Current
Not much to add to the commands above.... brew installs some extra dependencies like readline and sqlite and some extra packages that are needed for the steps below like disutils and pip (not really sure how it did this).

numpy and scipy

numpy and scipy provide python wrappers to linear algebra packages and additional compiled computational code. Online I have seen people have issues trying to install them with pip. I tried to install from source following the instructions from scipy and had moderate but not full success (really, full success for numpy, partial success for scipy). What ended up working best for me was installing using a third-party brew tap:
brew tap samueljohn/python
brew install numpy --HEAD
brew install scipy --HEAD
These commands installs the latest dev versions of numpy and scipy from github. They also include some dependencies like nose (python module), suite-sparse (brew formula), and swig (brew formula).
You can run numpy and scipy's unit tests to see if the installation went okay. I found that scipy's test generated tons of errors or warnings. Talking to the developers and other users, I learned that these were okay and were the result of the tests not being well written for builds using Apple's Accelerate framework for the linear algebra package. This package is the best choice because it is optimized for Apple's Intel processors. Building an optimized linear algebra package from source is highly non-trivial.
A better way to test the numpy/scipy installation is to run some code representing typical usage that you know works or to run the unit tests of a program that uses. For example, I trust that the errors I saw in scipy's unit tests are not critical because qutip ran all of its tests successfully (plus the developers also say the test results are not a problem).

matplotlib and ipython

* matplotlib and ipython For matplotlib and ipython, I just used pip: pip install matplotlib pip install ipython
To use all of the features of ipython, you need Qt and zmq.
* Qt I did this, but I don't think it's necessary because the brew pyqt formula installs qt on its own: (I downloaded the Qt library installer from . Only the library is necessary (previously I downloaded the SDK which puts a lot of extra stuff on your computer). I got the open source libraries -- not sure if there are other versions available.)
After Qt, you need PyQt which I got by brew install pyqt and then adding to .bash_profile: export PYTHONPATH=/usr/local/lib/python:$PYTHONPATH
The PyQt formula adds some dependencies like sip and libpng.
* zmq Again I used brew: brew install zmq For the rest of the dependencies I used I used pip: pip install pyzmq pip install pygments pip install tornado
* ipython usage To use ipython as an interactive shell with function documentation popups and syntax highlighting, do: ipython qtconsole To enable plots to appear within the shell output rather than in separate windows, use the qtconsole with the pylab inline option: ipython qtconsole --pylab=inline To use ipython as a browser based notebook that can be saved and reopened, use ipython notebook To use a non-default browser like safari or firefox, use the --browser option: ipython notebook --browser=firefox For some reason, Google Chrome is not recognized by python. For it you have to use: BROWSER=/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome ipython notebook or (if you don't want ipython to open a new tab because Chrome will keep the tab open from last time): ((sleep 1 && /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome ) &) ; (ipython notebook --no-browser) In the latter, the sleep command gives ipython a chance to boot up its server before Chrome can load and say the page was not found. The command after a && is not executed until the command before it terminates successfully. bash runs commands surrounded by "(" and "&)" as background processes and executes commands separated by ";" simultaneously.

Spyder

Spyder has a few more recommended modules that were not installed above. I installed all of them via pip: pyflakes, rope, sphinx, pylint, and pep8. Spyder itself can also be installed via pip.

wxPython

I installed wxPython with brew install wxPython.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home