3

I'm currently running Python 3.7 and also working in Visual Code through Anaconda, thus I have 2 separate install locations for modules. How can I look and see what Python modules are installed and what their current versions are?

Is there a way to do this without looking in the site-packages library one-by-one?

For instance, I want to make sure pandas, pyinstaller, pyqt5, tkinter, and more are the both installed in each directory and both the same version.

EDIT - Not the same question as How can I get a list of locally installed Python modules?, as pip 10 has been updated and the code provided in the answer no longer works.

MacItaly
  • 345
  • 4
  • 16

2 Answers2

2

You can do this:

import pip
installed_packages = pip.get_installed_distributions()
installed_packages_list = sorted(["%s==%s" % (i.key, i.version)
     for i in installed_packages])
print(installed_packages_list)

It returns a list of the packages intalled on your machine with their version number !

Best

Maxouille
  • 2,729
  • 2
  • 19
  • 42
  • 1
    https://docs.python.org/3/library/pkgutil.html#pkgutil.iter_modules to do it without dependencies on pip. – TkTech Mar 25 '19 at 15:59
  • Looks exactly similar to accepted answer in the above link in comment to question :P – Austin Mar 25 '19 at 15:59
  • AttributeError: module 'pip' has no attribute `get_installed_distributions` https://github.com/ARMmbed/mbed-cli/issues/657 – MacItaly Mar 25 '19 at 15:59
2

Looks like all you need is the pip list command on your terminal

Jjagwe Dennis
  • 1,643
  • 9
  • 13