相关疑难解决方法(0)

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

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

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

python-3.x jupyter-notebook jupyter-lab

8
推荐指数
1
解决办法
800
查看次数

标签 统计

jupyter-lab ×1

jupyter-notebook ×1

python-3.x ×1