I'm looking for a way to get a list of all installed/importable python modules from a within a Jupyterlab notebook.
From the command line, I can get the list by running
py -3 -m pip freeze
(or)
pip freeze
In the Jupyterlab console, running pip freeze returns
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/
For older versions of pip, it was possible to import pip and get a list from within a notebook.
The command was
help('modules')
This now gives a warning and returns nothing.
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)
10 year old stackoverflow solutions like How can I get a list of locally installed Python modules? also no longer work.
Is there a proper way of doing this (without using a subprocess hack or running pip as an external program like "!pip")
You may run following snippet to the result.
!pip list
you can also try
!pip freeze
in your jupyter notebook. Hope it helps you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With