IPython: Python at your fingertips by Fernando Pérez, Min Ragan-Kelley, Brian E. Granger, Thomas Kluyver¶
Presenters: Fernando Pérez and others
PyCon 2012 presentation page: https://us.pycon.org/2012/schedule/presentation/121/
Video running time: 39:58
(00:26) Talk in two parts:
- Brief overview of IPython
- Demo of the new IPython web notebook
Brief overview of IPython¶
the “I” in IPython is for “Interactive”.
In scientific computing, we typically don’t know what we’re doing.
Exploratory computing is not just for scientists.
Python an excellent base for an interactive environment¶
The default interactive environment is just a starting point.
$ python >>> ls ... NameError: name 'ls' is not defined >>> os? ... SyntaxError: invalid syntax >>> execfile('~/scratch/err.py') ... IOError: [Errno 2] No such file or directory '~/scratch/err.py' >>> execfile('/home/fperez/scratch/err.py') ... NameError: name 'foo33' is not defined
We can do better¶
$ ipython In : ls ~/scratch/err*py /home/fperez/scratch/err25.py ... In : os? (One question mark - Brings up a whole bunch of info about the os module) In: os?? (Two question marks - Brings up even more info, displaying the code if possible, syntax highlighted) ... In: run ~/scratch/error ... (Traceback in color and shows the relevant lines of code)
Terminal IPython vs. QT console vs. Web notebook¶
┌──────────────────┐ <=> | Terminal console | └──────────────────┘ ┌────────────────┐ ┌──────────────────┐ | IPython kernel | <=> | Qt Console | └────────────────┘ └──────────────────┘ ┌──────────────────┐ <=> | Web notebook | └──────────────────┘
(05:32) Several clients now.
(05:56) Qt console
- Feels like a terminal emulator
- But it’s a Qt rich text widget that can display graphics, color, multi-line editing, etc.
(06:41) Microsoft Visual Studio 2010 integrated console
(07:44) Browser-based notebook
- rich text
(08:30) Interactive and high-level parallel APIs
The same abstractions and communications machinery that controls a single interactive IPython instance can control multiple IPython instances.
Exposes an IPython cluster which consists of an IPython controller and one or more IPython engines.
Enables parallel computing.
A brief history of IPython¶
- October/November 2001: “just a little afternoon hack”
- $PYTHONSTARTUP: ipython-0.0.1.py (259 lines)
- IPP (Interactive Python Prompt) by Janko Hauser (Oceanography)
- LazyPython by Nathan Gray (CalTech)
- 2002: Drop John Hunter’s Gnuplot patches: matplotlib
- 2004: Brian Granger, Min Ragan-Kelly: Parallel on Twisted
- 2005-2009: Mayavi, Wx support, refactoring; slow period.
- 2010: Discover 0MQ, Enthought support.
- Move to Git/GitHub.
- Build Qt console (Evan Patterson)
- Rewrite parallel support with ZeroMQ.
- Python 3 port (Thomas Kluyver)
- 2011: Web Notebook
Demo of the web notebook¶
Tour of IPython notebook features¶
(19:43) pwd works
(19:48) mixing Python and shell - you can interpolate Python variables into shell using a $
You can paste code in with Python prompts and IPython will filter out the Python prompts
Highlight standard error
(21:00) IPython fetches output asynchronously
(21:15) Cause the kernel to segfault, but your document is saved so you can restart your kernel and get back to work
Displaying complex output types, such as images¶
(22:14) Can display arbitrary output types such as images and add your own representations
Displaying a local image
Displaying a remote image
Loading external code¶
- matplotlib gallery and other galleries
- Drag and drop a .py in the dashboard
- Use %loadpy with any local or remote url
Q: How to collaborate on an IPython notebook?
A: Unfortunately it’s fairly limited right now. You can share notebook files on GitHub. No real-time synchronization. You can share a notebook by sending a person the URL to the notebook (and you can enable SSL and password protection). One person has to save the notebook and the other person needs to reload it.
A: In a gist, we have a very simple reST exporter. Improving the exporter should be easy so that you can create a Sphinx-compatible notebook. It’s not hard to do, but we’re busy.
It looks like this might do the trick??? https://github.com/ipython/nbconvert
(38:32) Q: How feasible is it to use IPython as a replacement shell?
A: Ask Mark Wiebe of NumPy who uses the Qt console
(39:00) Q: Debugging in the interactive notebook?
A: If you type qtconconsole then you can connect to a running kernel. We also plan to expose it via the web.