Skip to content

Latest commit

 

History

History
358 lines (223 loc) · 11.2 KB

ipython.rst

File metadata and controls

358 lines (223 loc) · 11.2 KB

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/

Slides:

Video: https://www.youtube.com/watch?v=26wgEsg9Mcc&list=PLBC82890EA0228306&index=9&feature=plpp_video

Video running time: 39:58

Resources:

(00:26) Talk in two parts:

  1. Brief overview of IPython
  2. Demo of the new IPython web notebook

Brief overview of IPython

Why IPython?

(00:40)

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

(01:45)

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

(02:37)

$ ipython
In [1]: ls ~/scratch/err*py
/home/fperez/scratch/err25.py
...
In [2]: os?
(One question mark - Brings up a whole bunch of info about the os module)
In[3]: os??
(Two question marks - Brings up even more info, displaying the code if possible, syntax highlighted)
...
In[13]: run ~/scratch/error
...
(Traceback in color and shows the relevant lines of code)

Terminal IPython vs. QT console vs. Web notebook

(04:13)

┌──────────────────┐
<=> | 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

See http://pytools.codeplex.com/

(07:44) Browser-based notebook

  • rich text
  • code
  • plots...

(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

(10:20)

  • 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

Some quick stats

(13:06)

Support

(13:40)

IPython in brief

(14:06)

  • A better Python shell
  • Embeddable kernel and powerful interactive clients
    • Terminal
    • Qt console
    • Web notebook
  • Flexible parallel computing

Demo of the web notebook

(14:26)

An example of showing Twitter word frequencies

(14:40)

Tour of IPython notebook features

(19:32)

(19:43) pwd works

(19:48) mixing Python and shell - you can interpolate Python variables into shell using a $

Plotting

(20:17) matplotlib plots.

Niceties

You can paste code in with Python prompts and IPython will filter out the Python prompts

Highlight standard error

Detailed tracebacks

(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

Markdown

(21:42) You can create Markdown cells

Mathematics

(22:00) Mathematics including LaTeX and MathJax

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

image

Displaying a remote image

image

Embedding video

(23:29) Video - can embed videos like YouTube videos

Embedding iframes

(24:50)

Loading external code

(26:11)

  • matplotlib gallery and other galleries
  • Drag and drop a .py in the dashboard
  • Use %loadpy with any local or remote url

SymPy

(27:55)

IPython clusters

(29:42)

Conclusion

(35:20) Done with demo; we have a booth; we're having a sprint

Questions

(36:20)

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.

(37:40) Q: How to integrate with Sphinx?

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.