0%

python判断是不是在jupyter中

在jupyter中判断

1
2
3
4
import os
os.environ['_']

'/usr/bin/jupyter'

在终端交互环境判断

1
2
3
>>> import os
>>> os.environ['_']
'/usr/bin/python3'

为了使在jupyter里写的程序方便导出来,可以这样

1
2
3
4
5
import os
if "jupyter" in os.environ['_']:
from tqdm.notebook import tqdm
else:
from tqdm import tqdm