Say I have the following file t.py:
from IPython import get_ipython
if __name__ == '__main__':
ip = get_ipython()
if ip is not None:
print('Found IPython')
Here's what happens if I run it, with both Python and IPython:
% python t.py
% ipython t.py
Found IPython
Note that, only when running it with ipython, is get_ipython() not None.
Is there a way to start an IPython kernel from within the script, so that even if I run it as python t.py, then get_ipython() will not be None?
IPython.start_kernel()?IPython.kernelpackage has been deprecated since IPython 4.0." NOTE: When using theipython kernelentry point, Ctrl-C will not work. To exit, you will have to explicitly quit this process, by either sending "quit" from a client, or using Ctrl-\ in UNIX-like environments. To read more about this, see github.com/ipython/ipython/issues/2049 To connect another client to this kernel, use: --existing kernel-15293.json ```