Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using IPython from the Python shell like `code.interact()`

Is it possible to use the IPython shell from an existing Python shell, as a shell-inside-a-shell, similarly to the built-in code.interact()?

like image 367
Ram Rachum Avatar asked Aug 06 '10 12:08

Ram Rachum


3 Answers

In IPython 0.11 the API has been overhauled and the shell is even easier to invoke:

import IPython

IPython.embed()
like image 154
yac Avatar answered Oct 22 '22 01:10

yac


The recommended way of embedding IPython works fine:

~ $ python
Python 2.7 [...]
>>> from IPython.Shell import IPShellEmbed
>>> ipshell = IPShellEmbed()
>>> ipshell()

In [1]: 
like image 30
snapshoe Avatar answered Oct 22 '22 02:10

snapshoe


Django manage.py shell invoke a IPython shell when possible, and it's implemented like this:

import IPython

shell = IPython.Shell.IPShell()
shell.mainloop()
like image 23
satoru Avatar answered Oct 22 '22 03:10

satoru