检测笔记本是否以交互方式运行或在 nbconvert 中导出

Mas*_*rat 8 python ipython nbconvert

当我的笔记本使用 导出时,我想在代码中运行一些额外的检查nbconvert

有什么方法可以检测到这种情况吗?

我已经尝试了检测何时在 ipython 中交互式运行 python 脚本中的解决方案,但没有成功:一切都表明笔记本正在交互式运行。