Cookbook: Updating code for use with IPython 0.11 and later - ShuaiYAN/ipython GitHub Wiki

If you have Python code that imports IPython to start a REPL, you'll need to update it for version 0.11.

If you want to still support older versions, a try: except: block is probably the best way. The version number as a string is available as IPython.__version__.

If you're having trouble, talk to us on IRC or the mailing lists (links on the homepage).

Table of Contents

Namespace reorganization

Many functions and attributes previously available directly in IPython have been moved to IPython.core or IPython.lib

Starting IPython

embedded IPython does not load all configuration, and is often not what many users who use IPython.embed() actually want. Specifically, embedded IPython skips the namespace initialization steps (running startup files, etc.). If you want to start a regular IPython session, that has changed:

Old code:

from IPython.Shell import make_IPython
shell = make_IPython()
shell()

New code:

from IPython.frontend.terminal.ipapp import TerminalIPythonApp
app = TerminalIPythonApp.instance()
app.initialize(argv=[]) # argv=[] instructs IPython to ignore sys.argv
app.start()

Embedding API

Embedding IPython means putting IPython into a particular namespace (like a debugger). This is often not actually what people want, and you may want to check out the above code for starting 'regular' IPython.

  • IPython.Shell.IPShellEmbed moved to IPython.frontend.terminal.embed.InteractiveShellEmbed, embed is accessible from IPython too.
Old code:
import IPython
argv = ["-prompt_in1", "myprompt [\\#]> ",
        "-prompt_out", "myprompt [\\#]: ",
        "-profile", ipythonprofile]
shell = IPython.Shell.IPShellEmbed(argv=argv, user_ns=namespace)
shell.set_banner(shell.IP.BANNER + '\n\n' + banner)
shell.IP.user_ns = {}
shell()

New code:

import IPython
from IPython.config.loader import Config
cfg = Config()
cfg.InteractiveShellEmbed.prompt_in1="myprompt [\\#]> "
cfg.InteractiveShellEmbed.prompt_out="myprompt [\\#]: "
cfg.InteractiveShellEmbed.profile=ipythonprofile
# directly open the shell
IPython.embed(config=cfg, user_ns=namespace, banner2=banner)
# or get shell object and open it later
from IPython.frontend.terminal.embed import InteractiveShellEmbed
shell = InteractiveShellEmbed(config=cfg, user_ns=namespace, banner2=banner)
shell.user_ns = {}
shell()

Custom interact loop

Parallel

The parallel processing features have a completely new api. See the documentation for details

IPython directive

There is a new version in the ipython source: docs/sphinxext/ipython_directive.py but it may still contain bugs.

Example patches with < 0.11 compatibility

⚠️ **GitHub.com Fallback** ⚠️