我有一个模块(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.")
答案 0 :(得分:3)
# either:
from tqdm.autonotebook import tqdm
# or to suppress the warning:
from tqdm.auto import tqdm