Python检查jupyter笔记本或实验室是否正在运行

时间:2018-06-18 19:01:25

标签: python-3.x jupyter-notebook jupyter-lab

我有一个模块(tqdm),我需要进行不同的导入,具体取决于我是否在jupyter笔记本或jupyter实验室环境中运行.ipynb。有没有办法在python中确定这个?例如:

if <jupyter notebook>:
    from tqdm import tqdm_notebook as tqdm 
elif <jupyter lab>:
    from tqdm import tqdm
else:
    print("Not in jupyter environment.")

1 个答案:

答案 0 :(得分:3)

# either:
from tqdm.autonotebook import tqdm
# or to suppress the warning:
from tqdm.auto import tqdm