Wednesday, March 14, 2012

IPython Notebook

Interactive Python in your browser

IPython is a souped up Python shell with features such as inline help, tab completion, enhanced support for NumPy, SciPy and Matplotlib and a host of magic functions (IPython commands that begin with %).

But with version 0.12, IPython it goes one step further. It now introduces a web-based notebook. This means that you can access IPython running as a web server, either on your local machine or on a server on the network, and access the same interactive Python shell through your browser. You get support for rich media, text code, mathematical expressions and inline plots. You can send a notebook to a friend and the friend can simply run the notebook to see the code, your documentation and comments as well as output. The possibilities are limitless. You could run your own IPython notebook server and access it from anywhere through the network, to code, develop, test and/or run Python code.

Here are the dependencies:
  1. IPython version 0.12 or higher. If you have an older version, do easy_install -U ipython
    If you don't have easy_install, you can install it using setuptools either from your operating system package manager (GNU/Linux) or download and install (Microsoft Windows) with
    python setup.py
  2. Tornado version 2.2. Tornado is a Python web server. If you don't have Tornado installed, install it with the command easy_install tornado
You are now ready to run IPython notebook server. You can open a console (GNU/Linux) or an MS-DOS prompt (Microsoft Windows) and run the command

prompt>ipython notebook

This will run the Tornado web server and automatically open your browser showing you a web GUI. You can see the IPython prompt and start typing Python code. When done, press Shift+Enter to execute the code and see the results. To shutdown the IPython notebook server, go back to the console/MS-DOS Prompt and press Ctrl+C.

If you work with NumPy, SciPy and Matplotlib and don't want to bother with importing these modules each time. Simply start IPython notebook server as follows:

prompt>ipython notebook --pylab

To see inline graphs within the browser (instead of them popping up), use the following command to start IPython notebook server

prompt>ipython notebook --pylab inline

You can create a new notebook, save it for use in subsequent sessions, download notebooks to your local storage and upload notebooks from your computer to the notebook server. Here is a screencast (no audio on this one, sorry) to demonstrate basic features of IPython notebook server on Microsoft WIndows. I also tried it on Ubuntu 11.10 and it worked without a hitch.




No comments:

Post a Comment

Your comments are ciritical input for the sustainance and improvement of this blog.