title: How can I see all installed Python modules in Jupyter Lab (like pip freeze) with Python 3.7 or newer?
body: <p>I'm looking for a way to <strong>get a list</strong> of <strong>all installed/importable python modules</strong> from a within a Jupyterlab notebook.</p>
  
  <p>From the command line, I can get the list by running</p>
  
  <pre><code>py -3 -m pip freeze
  </code></pre>
  
  <p>(or)</p>
  
  <pre><code>pip freeze
  </code></pre>
  
  <p>In the Jupyterlab console, running pip freeze returns</p>
  
  <pre><code>The following command must be run outside of the IPython shell:
  
      $ pip freeze
  
  The Python package manager (pip) can only be used from outside of IPython.
  Please reissue the `pip` command in a separate terminal or command prompt.
  
  See the Python documentation for more information on how to install packages:
  
  https://docs.python.org/3/installing/
  </code></pre>
  
  <p>For older versions of pip, it was possible to import pip and get a list from within a notebook.</p>
  
  <p>The command was </p>
  
  <pre><code>help('modules')
  </code></pre>
  
  <p>This now gives a warning and returns nothing.</p>
  
  <pre><code>c:\python37\lib\site-packages\IPython\kernel\__init__.py:13: ShimWarning: The `IPython.kernel` package has been deprecated since IPython 4.0.You should import from ipykernel or jupyter_client instead.
    "You should import from ipykernel or jupyter_client instead.", ShimWarning)
  </code></pre>
  
  <p>10 year old stackoverflow solutions like <a href="https://stackoverflow.com/questions/739993/how-can-i-get-a-list-of-locally-installed-python-modules">How can I get a list of locally installed Python modules?</a> also no longer work.</p>
  
  <p>Is there a proper way of doing this (without using a subprocess hack or running pip as an external program like "!pip")</p>