Search code examples
ipythonpython-traitlets

How do you embed an ipython console with exec_lines?


I'm trying to embed an ipython console into my command line application. I have the following:

import IPython
from traitlets.config import Config
c = Config()
c.InteractiveShellApp.exec_lines = [
    'import matplotlib.pyplot as plt',
    '%matplotlib',
]
return IPython.start_ipython(config=c, user_ns=globals())

However, it seems to completely ignore the "exec_lines" part since plt is not available.


Solution

  • See: Can you specify a command to run after you embed into IPython?

    IPython.start_ipython(config=c, user_ns=locals())