IPython is a Read-Evaluate-Print Loop shell for interactive Python development. It supports interactive visualizations using GUI toolkits, and provides a kernel for Jupyter. It can also be embedded into other projects.
There are other similar REPL shells for Python, for example, ptpython and bpython.
Version | Release Date |
---|---|
5.0.0 | 2016-07-07 |
4.2.0 | 2016-04-20 |
4.1.0 | 2016-02-02 |
4.0.0 | 2015-08-12 |
3.2.0 | 2015-06-21 |
3.1.0 | 2015-04-03 |
3.0.0 | 2015-02-27 |
2.4.0 | 2015-01-30 |
2.3.0 | 2014-10-01 |
2.2.0 | 2014-08-06 |
2.1.0 | 2014-05-21 |
2.0.0 | 2014-04-02 |
0.13 | 2012-06-30 |
0.12 | 2011-12-19 |
0.11 | 2011-07-31 |
0.10 | 2010-09-01 |
0.9 | 2008-09-13 |
Like the built-in python
interactive shell, IPython is a REPL (Read-Evaluate-Print Loop) shell, with a variety of features that make it more pleasant to use for day-to-day Python development than the built-in REPL shell.
To install it:
pip install ipython
Or, via Anaconda:
# To install into the active environment:
$ conda install ipython
# Or, to create a new environment with IPython installed:
$ conda create -n <env_name> ipython
Or, via Enthought Canopy:
$ enpkg ipython
After installation, run it using your default Python (2 or 3) using:
ipython
Or to use Python 3:
ipython3
?
This gives you an introduction and overview of IPython's features.
object?
This lists all methods and fields of the object and its documentation (if it exists).
object??
Same as above, provides even more detail about the object, in particular will try to find and display the source code for the object.
object.<TAB Key>
TAB-completion that lists and iterates through available fields/methods of an object. Due to the dynamic nature of Python not all methods can be discovered this way. Also private methods (starting with _
) will be hidden by default, insert a _
and press TAB again to display them.
%quickref
This displays a quick-reference for the IPython shell.
IPython has two parts to it: A command line interface that replaces the default python
REPL and a way to run Python through the web browser as a graphical user interface.
With the latest developments the browser part has been split into the Jupyter project that enables multiple programming languages to use the graphical interface. It is still possible to use IPython as a Python kernel for this.
Up to date setup instructions for Jupyter can be found in the official install docs.
ipython
, or jupyter console
, when invoked from the command line without any other parameters will enter an interactive terminal session as below:
jupyter qtconsole
, or ipython qtconsole
before version 5, will start a multi-tabbed QT based console:
jupyter notebook
, or ipython notebook
before version 5, will start a server and by default open up a web page, at http://localhost:8888/tree
, with the "Home" view of the current directory. This allows you to open existing notebooks or new kernels in several languages, depending on which you have installed; each will be opened in a new browser tab.
Notebooks allow you to mix markdown, including MathJax, code from the kernel of your choice, plots and graphs, images and even videos.
%paste
This is the primary Magic Method for pasting. It directly pastes text from the system clipboard, intelligently handling common issues with newlines and indentation.
%cpaste
If you are using IPython via SSH, use %cpaste
instead, as it does not need to access the remote system clipboard.
Since IPython 5.0.0, the improved prompt toolkit should directly handle pasting multi-line code without the need for %paste
or %cpaste
.
%storemagic
stores variables and macros on IPython's database.
To automatically restore stored variables at startup add this to ipython_config.py
:
c.StoreMagic.autorestore = True
Example:
In [1]: l = ['hello',10,'world']
In [2]: %store l
In [3]: exit
(IPython session is closed and started again...)
ville@badger:~$ ipython
In [1]: l
Out[1]: ['hello', 10, 'world']
Note:
It should be noted that if you change the value of a variable, you need to %store it again if you want to persist the new value.
Note also that the variables will need to be pickleable; most basic python types can be safely %storeād.