Reputation: 7329
I have a module (tqdm) that I need to import differently depending on whether I'm running my .ipynb
in a jupyter notebook or jupyter lab environment. Is there way that I can determine this in python? For example:
if <jupyter notebook>:
from tqdm import tqdm_notebook as tqdm
elif <jupyter lab>:
from tqdm import tqdm
else:
print("Not in jupyter environment.")
Upvotes: 14
Views: 3309
Reputation: 14799
# either:
from tqdm.autonotebook import tqdm
# or to suppress the warning:
from tqdm.auto import tqdm
For other modules/checks, see How can I check if code is executed in the IPython notebook? (But note that the accepted albeit unpopular answer there is "this is intentionally not meant to be possible by design.")
Upvotes: 5