How to get list of installed Packages?

You can use this simple command from the cmd prompt.

There are two command available to list all the installed packages.

1. pip list
2. pip freeze

Both these commands will list all the installed packages along with the version numbers.

Lets see how to get the same within a Python program.

Python to List installed Packages

This program also uses the pip services to get the list.

The code is not much complex. It is only few lines of code.

#To get list of packages installed
import pip

#Get installed distributions varies depending on pip
try:
    from pip import get_installed_distributions
except:
    from pip._internal.utils.misc import get_installed_distributions

#Get all installed package distributions
#Print installed module path, name & version
for i in get_installed_distributions():
    print(i.location,i.key, i.version)

Using this list, you can decide to update any package to its latest version and uninstall any unwanted packages from the install library.

Leave a Reply