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.
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.
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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With