Python check if jupyter notebook or lab is running

ε祈祈猫儿з 提交于 2021-01-27 04:00:40

问题


I have a module (tqdm) that I need to import differently depending on whether I'm running my .ipynb in a jupyter notebook or jupyter lab environment. Is there way that I can determine this in python? For example:

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

回答1:


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


来源:https://stackoverflow.com/questions/50915913/python-check-if-jupyter-notebook-or-lab-is-running

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!