(Python) ipython

When I was just peeping into the discussions at #python, I saw a few talking about ipython. On first look, I thought it to be Iron Python stuff but was wrong. It is an (another?) enhanced Python Shell or what we otherwise call as Interactive Python Mode. The good thing with these stuffs is you can just download and try them, not much a paining process to get them working. Hence I went for it.


  • Dynamic Object Introspection : We can access docstrings, function definition prototypes, source codes of modules, source files and a lot more dynamically.

For example, after importing `os` module, typing os.path?? or os.path? gives complete source code and description of the os module respectively. Similarly `%pdoc object`gives us the object’s doctstring information.

  • Local namespace completion with TAB press.
  • Numbered input/output prompts.

In [1]: print "Hello World!"
Hello World!

In [2]: (1+2)*3
Out[2]: 9

  • User-extensible`magic` commands (type %magic for information).
  • System shell access with ! prefix.

!ls will issue the `ls` command in the system shell and print its output.

  • File system navigation with %cd command.
  • Verbose and colored exception traceback.
  • Auto-parenthesis.

>>> callable_ob arg1, arg2, arg3
and the input will be translated to this:
--> callable_ob(arg1, arg2, arg3)

  • Auto-quoting.

>>> ,my_function a b c # becomes my_function("a","b","c")
>>> ;my_function a b c # becomes my_function("a b c")

  • Embeddable within other python code/modules.


I always prefer the `svn checkout` way of getting the source code. We can get to know more about ipython at its home site. We can also get pythonreadline from the same site, which helps us to have features like color, tab, completion, etc. (I read somewhere that it is not needed for ipython as it implicitly has pyreadline). The following are the steps to install ipython from the svn repos as a local copy,

  1. We can get the source code by doing an svn checkout,
  2. svn co http://ipython.scipy.org/svn/ipython/ipython/trunk ipython

  3. We need to get into the checked out source directory and run the following command
  4. python setup.py install

  5. The –home option can be used to specify a directory to install the ipython, else it will install in the default python directories.
  6. python setup.py install --home /home/myuser/python/ipython

  7. If we are using –home option, then we need to add the following line into our.bashrc. Else we need to export the PYTHONPATH variable every time adding the path of our ipython/lib/python installation to it.
  8. export PYTHONPATH=/home/myuser/python/ipython/lib/python

  9. We can run ipython by executing ipython/bin/ipython from the shell (or create a link pointing to this file).

The complete documentation can be obtained as pdf as well as viewed as HTML.


One thought on “(Python) ipython

  1. ipython is great for playgrounding scripts. I love the magic command %logstart that creates a logfile in your cwd, logging input into the interpretor. Coupling the auto-logging with good commenting has pushed my python coding skill above abysmal in the weeks that I’ve been using it.

    django also has some intergration with ipython, although I haven’t explored any of this.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ 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