The Python Oracle

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

Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn

--

Music by Eric Matyas
https://www.soundimage.org
Track title: Over a Mysterious Island Looping

--

Chapters
00:00 Question
00:19 Accepted answer (Score 656)
03:03 Answer 2 (Score 1216)
03:16 Answer 3 (Score 336)
04:16 Answer 4 (Score 143)
04:45 Thank you

--

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

Accepted answer links:
[god forbid]: https://stackoverflow.com/questions/3220...

--

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().