Search code examples
pythonshellcommand-linepython-3.xipython

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


I would like to add some commandline options to a python launch code in order to actually invoke an ipython shell. How do I do that?


Solution

  • To start IPython shell directly in Python:

    from IPython import embed
    
    a = "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