How to Show Packages in Python

In this tutorial, we will learn some of the different ways to list what packages are installed in your active version of Python.

 

List Python Packages with PIP

The easiest way to get the installed Python packages is by asking the pip package manager to show them. pip provides two commands for this, list and freeze. list returns every package no matter if they were installed by pip or not and freeze shows only packages installed by pip.

 

pip list
Package  Version
---------- -------
asgiref  3.3.4
Django   3.2.4
pip    21.1.2
pytz    2021.1
setuptools 57.0.0
sqlparse  0.4.1
wheel   0.36.2

 

pip freeze
asgiref==3.3.4
Django==3.2.4
pytz==2021.1
sqlparse==0.4.1

 

Narrow Down The Results

If you have a lot of packages and need to narrow down the matches, pipe the grep command and type some of the package name as the first argument.

 

pip list | grep django -i
Django   3.2.4

 

Note – the i flag is to make the search case insensitive. For more info read how to use the grep command.

 

Get all Modules Available from within Python

If you need to see every single module available to Python, jump into a Python console from a terminal window and use help() function like this:

 

python3
help("modules")
Please wait a moment while I gather a list of all available modules...

...
__future__     _testcapi      functools      rlcompleter
_abc        _testimportmultiple gc         runpy
...