7

Before switching to IPython v0.11 (using Python 2.6.1), it was possible to embed an interactive IPython shell using for example this, e.g.

from IPython.Shell import IPShellEmbed
ipshell = IPShellEmbed()
ipshell() # this call anywhere in your program will start IPython

"The embedded shell has been refactored into a truly standalone subclass of InteractiveShell called InteractiveShellEmbed. All embedding logic has been taken out of the base class and put into the embedded subclass" (see here and here).

The way I understand it you should now be able to simply start a console by

import IPython
IPython.embed()

However, this raises

TraitError: The 'exit_msg' trait of an InteractiveShellEmbed instance must be a string, but a value of u'' was specified.

If we pass a string for exit_msg by

IPython.embed(exit_msg='Whatever')

Then it raises a different error

AttributeError: 'InteractiveShellEmbed' object has no attribute 'set_completer'

Did anybody else encounter this problem? Otherwise this might be a bug since it is a developer version after all.

Community
  • 1
  • 1
Alain
  • 5,525
  • 4
  • 16
  • 6

2 Answers2

10

These days (3.0+) all you need to do is:

from IPython import embed; embed()

If you mean embedding another IPython shell in IPython (recursively), there was a long time that this was not supported, but that problem was patched last year.

Jason Newton
  • 1,201
  • 9
  • 13
3

There are specific instructions on the github wiki:

from IPython.frontend.terminal.ipapp import TerminalIPythonApp
app = TerminalIPythonApp.instance()
app.initialize(argv=[]) # argv=[] instructs IPython to ignore sys.argv
app.start()
Jonathan Hendler
  • 1,239
  • 1
  • 17
  • 23