jupyter或jupyterlab中显示

jupyter或jupyterlab中显示

本文介绍了有没有一种方法可以检测到笔记本在voila,jupyter或jupyterlab中显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 xarray_leaflet 库,该库在笔记本启动时具有不同的行为瞧,jupyter或jupyterLab.

I'm using the xarray_leaflet library that has has a different behavior if the notebook is launch with voila, jupyter or jupyterLab.

有没有办法以编程方式检测到它?

Is there a way to detect it programmatically ?

推荐答案

在voila版本中> .2 ,正在运行的环境上有一堆环境变量(例如,'QUERY_STRING','SERVER_SOFTWARE','SERVER_PROTOCOL','SERVER_PORT','PATH_INFO','SERVER_NAME','SCRIPT_NAME'),因此检测您是否在voila中运行就像检查其中是否存在一样简单,甚至更好:

In versions of voila > .2, there are a bunch of environmental variables on the running environment (e.g. 'QUERY_STRING', 'SERVER_SOFTWARE', 'SERVER_PROTOCOL', 'SERVER_PORT', 'PATH_INFO', 'SERVER_NAME', 'SCRIPT_NAME'), so detecting if you are running in voila is as simple as checking if any of those exist, or even better:

import os
running_in_voila = os.environ.get('SERVER_SOFTWARE','jupyter').startswith('voila')

这篇关于有没有一种方法可以检测到笔记本在voila,jupyter或jupyterlab中显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 01:19