Issue
For my IPython QtConsole, I have a startup script in my profile_default/startup
folder, which contains the following lines:
ipy = get_ipython()
try:
plot
except NameError: # not loaded yet
ipy.run_line_magic("pylab", "inline")
This works fine in the QtConsole and Notebook, but if I now run ipython
with no subcommand, i.e. in the Windows command line, it prints an error that the 'inline' GUI is invalid.
Is there any way I can check for the subcommand (qtconsole, notebook or "None") inside the startup script, so I can avoid that message?
(IPython QtConsole 3.2.0, WinPython-64bit-3.4.3.4)
Solution
I'm going to assume that ipy
is the result of get_ipython()
.
Warning: You should not try to have code that behave differently on various frontend. It will break at some point, and lead to hard to debug issues that don't make sens. Nasal demons will be on a the lookout for the smallest misstep to haunt you.
That being say, in the pure, classical terminal IPython you can can verify that:
In [1]: type(get_ipython())
Out[1]: IPython.terminal.interactiveshell.TerminalInteractiveShell
Which is not true for Notebook and QtConsole (which are ZMQInteractiveShell
). In both case IPython.terminal.interactiveshell.TerminalInteractiveShell
should be importable, and you can check with issubclass
in which case you are.
Now, you can also create your own aliases on windows (not sure how), that pass extra command line arguments to IPython, in order for notebook
and qtconsole
to not have the same startup sequence.
Answered By - Matt
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.