Aus*_*tin 8 python-3.x jupyter-notebook jupyter-lab
我有一个模块(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)
# either:
from tqdm.autonotebook import tqdm
# or to suppress the warning:
from tqdm.auto import tqdm
Run Code Online (Sandbox Code Playgroud)
对于其他模块/检查,请参阅如何检查代码是否在 IPython 笔记本中执行?(但请注意,尽管不受欢迎,但已被接受的答案是“这并不是有意设计成可能的。”)
| 归档时间: |
|
| 查看次数: |
800 次 |
| 最近记录: |