as-is True
to-be True
Am I in a notebook? True

in_ipython[source]

in_ipython()

Check if the code is running in the ipython environment (jupyter including)

as-is True

in_ipython2[source]

in_ipython2()

to-be True
Am I in a notebook? True
from nbdev.export import notebook2script
notebook2script('73_in_ipython.ipynb')
Converted 73_in_ipython.ipynb.
!ipython decision_tree/test/in_ipython.py 
]0;IPython: pete88b/decision_tree
as-is True
to-be True
Am I in a notebook? False
!python decision_tree/test/in_ipython.py 
as-is True
to-be False
Traceback (most recent call last):
  File "decision_tree/test/in_ipython.py", line 32, in <module>
    from nbdev.imports import IN_NOTEBOOK
  File "/home/peter/github/pete88b/nbdev/nbdev/__init__.py", line 6, in <module>
    from .flags import *
  File "/home/peter/github/pete88b/nbdev/nbdev/flags.py", line 90, in <module>
    for fn in fns: register_line_magic(fn)
  File "/home/peter/anaconda3/envs/nbdev-fork/lib/python3.7/site-packages/IPython/core/magic.py", line 229, in magic_deco
    raise NameError('Decorator can only run in context where '
NameError: Decorator can only run in context where `get_ipython` exists

why is it a problem

__init__.py and flags.py use IN_IPYTHON to know if magic flags should be created or not.

In the example above, IN_IPYTHON is True but we fail to create magics because we can't access the get_ipython function.