Can you specify a command to run after you embed into IPython?
The document stated that IPython.start_ipython
reads the configuration file, while IPython.embed
does not. With that in mind, let's use the former:
import IPython
c = IPython.Config()
c.InteractiveShellApp.exec_lines = [
'%pylab qt4',
"print 'System Ready!'",
]
IPython.start_ipython(config=c)
Update
I am not sure what you meant by to keep the current namespace. If you meant local/global variables:
IPython.start_ipython(config=c, user_ns=locals()) # Pass in local variables
IPython.start_ipython(config=c, user_ns=globals()) # Pass in global variables
The IPython.config
package has been deprecated since IPython 4.0. You should import from traitlets.config instead.
import IPython
from pkg_resources import parse_version # installed with setuptools
if parse_version(IPython.release.version) >= parse_version('4.0.0'):
from traitlets.config import Config
else:
import IPython.config
from IPython.config import Config
c = Config()
c.InteractiveShellApp.exec_lines = [
'%pylab qt4'
"print('System Ready!')",
]
IPython.start_ipython(config=c)