Josh Josh - 1 year ago 89
Python Question

ipython --pylab vs ipython

What does

ipython --pylab
exactly do?

ipython --pylab
exactly equivalent to:

> ipython
> from pylab import *

If not, what are the differences?

Say I launch IPython without the
arguments, how can I bring it to the same state as if I had started it with

Answer Source

--pylab[=option] is almost technically equivalent to %pylab option as the difference that you cannot un-pylab a --pylab kernel, but you can restart a %pylab kernel.

%pylab is a little more that just from pylab import * (see %pylab?for a longer explanation), but in short yes it imports a lot of things, but it also hooks event loops (qt, wx, osx...) and set-up some display hooks for matplotlib (the things that magically allow you to get inline graph). Setting the display-hook is closer to something like sympy.init_printing() if you wonder.

Note that starting at IPython 1.0 we recommend not to use --pylab or %pylab (unless you know exactly the implication). We provide %matplotlib that only init the display hook. %pylab will warn you if it replaced a few object in current namespace, and which ones. This is useful especially for functions like sum which do not have the same behavior the behavior with and without pylab and leads to subtle bugs.

We consider now that --pylab was a mistake, but that it was still really usefull at the beginning of IPython. We all know that Explicit is better than implicit so if you can advise people not to use %pylab we would appreciate it, to one day get rid of it.

Extract from %pylab help that give only the import part of pylab:

%pylab makes the following imports::

import numpy
import matplotlib
from matplotlib import pylab, mlab, pyplot
np = numpy
plt = pyplot

from IPython.display import display
from IPython.core.pylabtools import figsize, getfigs

from pylab import *
from numpy import *