The Python Oracle

How do I get a list of locally installed Python modules?

--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Puzzling Curiosities

--

Chapters
00:00 How Do I Get A List Of Locally Installed Python Modules?
00:12 Answer 1 Score 1279
00:21 Answer 2 Score 355
01:05 Answer 3 Score 95
01:24 Answer 4 Score 161
01:48 Thank you

--

Full question
https://stackoverflow.com/questions/7399...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #module #pip

#avk47



ANSWER 1

Score 1279


help('modules')

in a Python shell/prompt.




ANSWER 2

Score 355


Now, these methods I tried myself, and I got exactly what was advertised: All the modules.

Alas, really you don't care much about the stdlib. You know what you get with a Python install.

Really, I want the stuff that I installed.

What actually, surprisingly, worked just fine was:

pip freeze

Which returned:

Fabric==0.9.3
apache-libcloud==0.4.0
bzr==2.3b4
distribute==0.6.14
docutils==0.7
greenlet==0.3.1
ipython==0.10.1
iterpipes==0.4
libxml2-python==2.6.21

I say "surprisingly", because the package install tool is the exact place one would expect to find this functionality, although not under the name 'freeze', but Python packaging is so weird that I am flabbergasted that this tool makes sense. Pip 0.8.2 and Python 2.7.




ANSWER 3

Score 161


Since pip version 1.3, you've got access to:

pip list

Which seems to be syntactic sugar for "pip freeze". It will list all of the modules particular to your installation or virtualenv, along with their version numbers. Unfortunately, it does not display the current version number of any module, nor does it wash your dishes or shine your shoes.




ANSWER 4

Score 95


  • In ipython you can type "importTab".

  • In the standard Python interpreter, you can type "help('modules')".

  • At the command-line, you can use pydoc modules.

  • In a script, call pkgutil.iter_modules().