title: Check if module is running in Jupyter or not
body: <p>I'm looking for a reliable way to figure out if my module is being loaded/run from within a Jupyter notebook, or more specifically, if <code>ipywidgets</code> is available.</p>
  
  <p>This is not a duplicate of other questions: everything else I've found either has no reliable solution, or (more often) they use the "just try it and fail gently" approach that's common in Python. In my case, I'm trying to write the following logic:</p>
  
  <pre><code>if in_jupyter():
      from tqdm import tqdm_notebook as tqdm
  else:
      from tqdm import tqdm
  </code></pre>
  
  <p>I don't think "try and fail" is an appropriate solution here since I don't want to produce any output yet.</p>
  
  <p>The closest I've found to a solution so far is:</p>
  
  <pre><code>from IPython import get_ipython
  get_ipython().config['IPKernelApp']['parent_appname'] == 'ipython-notebook'
  </code></pre>
  
  <p>but this configuration property is some seemingly empty <code>traitlets.config.loader.LazyConfigValue</code> (<code>.get_value(None)</code> is just an empty string).</p>