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

前端 未结 30 2160
庸人自扰
庸人自扰 2020-11-22 04:32

I would like to get a list of Python modules, which are in my Python installation (UNIX server).

How can you get a list of Python modules installed in your computer?

相关标签:
30条回答
  • 2020-11-22 04:53

    Try these

    pip list
    

    or

    pip freeze
    
    0 讨论(0)
  • 2020-11-22 04:55

    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.

    0 讨论(0)
  • 2020-11-22 04:55

    Very simple searching using pkgutil.iter_modules

    from pkgutil import iter_modules
    a=iter_modules()
    while True:
        try: x=a.next()
        except: break
        if 'searchstr' in x[1]: print x[1]
    
    0 讨论(0)
  • 2020-11-22 04:55

    on windows, Enter this in cmd

    c:\python\libs>python -m pip freeze
    
    0 讨论(0)
  • 2020-11-22 04:56
    help('modules')
    

    in a Python shell/prompt.

    0 讨论(0)
  • 2020-11-22 04:57

    Here is a python code solution that will return a list of modules installed. One can easily modify the code to include version numbers.

    import subprocess
    import sys
    from pprint import pprint
    
    installed_packages = reqs = subprocess.check_output([sys.executable, '-m', 'pip', 'freeze']).decode('utf-8')
    installed_packages = installed_packages.split('\r\n')
    installed_packages = [pkg.split('==')[0] for pkg in installed_packages if pkg != '']
    pprint(installed_packages)
    
    0 讨论(0)
提交回复
热议问题