This very page is a Jupyter notebook, so if you are reading this on a static web page, you should download the notebook file (which has the file extension .ipynb
) and open it with Jupyter/IPython (see below for how that's done).
The IPython (I guess that's short for interactive Python) kernel can be used in 3 quite different ways:
The classic IPython console runs in a terminal window (or on a real terminal, if those still exist) and is somewhat similar to the native interactive Python interpreter.
However, it has many significant improvements like tab-completion, color output, "magic" functions, the ability to run shell commands, ...
It can be started with
ipython3
Just give it a try!
If you are really into text-mode applications, you might also want to check out bpython and ptpython.
The Qt console uses the Qt GUI library but still keeps a terminal-like appearance.
The main difference to the classic console is the support for inline graphics/plots and multi-line editing.
It can be started with
ipython3 qtconsole
What are you waiting for? Go ahead and start it!
The Jupyter notebook (formerly known as IPython notebook) brings your interactive Python session into the browser and opens up a cornucopia of multi-medial greatness (to say the least).
Depending on your installation, the command for opening a notebook (like, for example, this very page) might be one of those:
ipython3 notebook
jupyter3
jupyter3 notebook
jupyter3-notebook
The commands on your system may have the digit 3
in it (to distinguish between Python 3.x and 2.x) or not (if you have only Python 3 installed, anyway).
If you don't know what's the deal with Python 2 vs. 3, just use Python 3!
The rest of this page describes the Jupyter notebook, but some of the commands are also available for the two console applications.
?
%quickref
qtconsole
can also be started from a running notebook session:
%qtconsole
range?
%whos?
%whos??
%pylab inline
Populating the interactive namespace from numpy and matplotlib
# TODO: TikZ extension?
%timeit?
# or:
#%run -t
%debug?
# or:
#%run -d
%who?
You can also do crazy things like running shell commands. You can even pass Python names and use the shell output again in Python:
extension = 'ipynb'
a =! ls *.$extension
a
['index.ipynb', 'intro-jupyter.ipynb', 'intro-numpy.ipynb', 'intro-python.ipynb', 'noise.ipynb', 'simple-signals.ipynb', 'template.ipynb']
d =! ddate
print(d.n)
Today is Setting Orange, the 67th day of Discord in the YOLD 3185
%%bash
tmp=$(tempfile).txt
echo some text > $tmp
echo more text >> $tmp
sed -i s/text/nonsense/ $tmp
cat $tmp
rm $tmp
some nonsense more nonsense
... but it doesn't stop there, you can also run Ruby, Octave or R code!
This is of course beyond the scope of this little tutorial, if you are interested, have a look at these commands:
%%ruby
%load_ext octavemagic
%%octave
%load_ext rmagic
%%R
See also Running Scripts from IPython
Show all available "magic" functions:
%lsmagic
Available line magics: %alias %alias_magic %autoawait %autocall %automagic %autosave %bookmark %cat %cd %clear %colors %conda %config %connect_info %cp %debug %dhist %dirs %doctest_mode %ed %edit %env %gui %hist %history %killbgscripts %ldir %less %lf %lk %ll %load %load_ext %loadpy %logoff %logon %logstart %logstate %logstop %ls %lsmagic %lx %macro %magic %man %matplotlib %mkdir %more %mv %notebook %page %pastebin %pdb %pdef %pdoc %pfile %pinfo %pinfo2 %pip %popd %pprint %precision %prun %psearch %psource %pushd %pwd %pycat %pylab %qtconsole %quickref %recall %rehashx %reload_ext %rep %rerun %reset %reset_selective %rm %rmdir %run %save %sc %set_env %store %sx %system %tb %time %timeit %unalias %unload_ext %who %who_ls %whos %xdel %xmode Available cell magics: %%! %%HTML %%SVG %%bash %%capture %%debug %%file %%html %%javascript %%js %%latex %%markdown %%perl %%prun %%pypy %%python %%python2 %%python3 %%ruby %%script %%sh %%svg %%sx %%system %%time %%timeit %%writefile Automagic is ON, % prefix IS NOT needed for line magics.
IPython can display all kinds of media and it can even handle the HTML5 <audio>
tag.