How can I launch ipython from shell, by running 'python ...'? How can I launch ipython from shell, by running 'python ...'? python-3.x python-3.x

How can I launch ipython from shell, by running 'python ...'?


To start IPython shell directly in Python:

from IPython import embeda = "I will be accessible in IPython shell!"embed()

Or, to simply run it from command line:

$ python -c "from IPython import embed; embed()"

embed will use all local variables inside shell.

If you want to provide custom locals (variables accessible in shell) take a look at IPython.terminal.embed.InteractiveShellEmbed


To do exactly what you asked for, i.e. add command line options to a python invocation to actually invoke IPython, you can do this:

python -c 'import subprocess; subprocess.call("ipython")'

I can't imagine, though, any circumstances where this would be useful.


Maybe an option is just to embed ipython in your code like this

def some_function():    some code    import IPython    IPython.embed()

When you run the function in some code it will launch and ipython terminal whose scope is the one of the function from where it was called.