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

前端 未结 30 2202
庸人自扰
庸人自扰 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 05:01

    Installation

    pip install pkgutil
    

    Code

    import pkgutil
    
    for i in pkgutil.iter_modules(None): # returns a tuple (path, package_name, ispkg_flag)
        print(i[1]) #or you can append it to a list
    

    Sample Output:

    multiprocessing
    netrc
    nntplib
    ntpath
    nturl2path
    numbers
    opcode
    pickle
    pickletools
    pipes
    pkgutil
    

提交回复
热议问题