如何解决如何判断环境是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 举报,一经查实,本站将立刻删除。