如何判断环境是Jupyter Notebook还是Jupyterlab?

问题描述

我有一个使用Ipywidgets支持Jupyter前端的Python模块。这在Jupyter Notebook中工作正常,但在Jupyterlab中无声地失败了,因为它们显然是don't allow arbitrary Javascript anymore。 Jupyterlab有一个Ipywidgets扩展,但是对于用户来说,这样做不是很明显,因此,如果当前上下文是Jupyterlab环境且未安装该扩展,我想显示一条消息。像这样:

def isIpy():
    try:
        __IPYTHON__
        return True
    except NameError: return False

if is_ipy():
    if <is_jupyterlab()> and not <has_widgets_extension()>: print('Use \'jupyter labextension install @jupyter-widgets/jupyterlab-manager\' to install the widgets extension')
    else: launchIpyWidgets() #This works fine
else: launchTkinterWidgets() #This also works fine

或者-也许最好-我可以在小部件显示中打勾:

from IPython.display import display
from ipywidgets import interactive,Layout,Accordion,HBox,VBox,HTML,Label,Button,FloatProgress
postinstruct = Label(value='After setting parameter values,run launchPlots() or start() to start the model.')
display(postinstruct)

if <failed to display>: print('Use \'jupyter labextension install @jupyter-widgets/jupyterlab-manager\' to install the widgets extension')

问题在于,在Jupyterlab中,它不会返回错误或显示小部件;它只会显示文本Label(value='Use…')

有什么主意如何可靠地检查这两项?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...