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).
Many functions and attributes previously available directly in IPython have been moved to IPython.core or IPython.lib
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 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 toIPython.frontend.terminal.embed.InteractiveShellEmbed
,embed
is accessible fromIPython
too.
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()
- see ipythons interact loop: https://github.com/ipython/ipython/blob/master/IPython/frontend/terminal/interactiveshell.py#L258
-
IPython.iplib.raw_input_original
->IPython.frontend.terminal.interactiveshell.raw_input_original
-
ipshell.IP.outputcache.prompt1
->ipshell.IP.displayhook.prompt1
-
IPython.utils.io.Term
->IPython.utils.io
, must be placed after instantiating the terminal
-
The parallel processing features have a completely new api. See the documentation for details
There is a new version in the ipython source: docs/sphinxext/ipython_directive.py but it may still contain bugs.
- embedded API:
- misc:
- AutoFormatedTB sugar-base