Python tqdm import 检查 jupyter notebook 或 lab 是否 运行
Python tqdm import check if jupyter notebook or lab is running
我有一个模块 (tqdm),我需要根据我是 运行 我的 .ipynb
在 jupyter notebook 还是 jupyter lab 环境中导入不同的模块。有什么办法可以在 python 中确定这一点?例如:
if <jupyter notebook>:
from tqdm import tqdm_notebook as tqdm
elif <jupyter lab>:
from tqdm import tqdm
else:
print("Not in jupyter environment.")
# either:
from tqdm.autonotebook import tqdm
# or to suppress the warning:
from tqdm.auto import tqdm
对于其他 modules/checks,请参阅 How can I check if code is executed in the IPython notebook?(但请注意,尽管不受欢迎,但已接受的答案是“这是有意设计的。”)
我有一个模块 (tqdm),我需要根据我是 运行 我的 .ipynb
在 jupyter notebook 还是 jupyter lab 环境中导入不同的模块。有什么办法可以在 python 中确定这一点?例如:
if <jupyter notebook>:
from tqdm import tqdm_notebook as tqdm
elif <jupyter lab>:
from tqdm import tqdm
else:
print("Not in jupyter environment.")
# either:
from tqdm.autonotebook import tqdm
# or to suppress the warning:
from tqdm.auto import tqdm
对于其他 modules/checks,请参阅 How can I check if code is executed in the IPython notebook?(但请注意,尽管不受欢迎,但已接受的答案是“这是有意设计的。”)