How to list all installed packages and their versions in Python?

前端 未结 12 1965
灰色年华
灰色年华 2020-12-12 10:07

Is there a way in Python to list all installed packages and their versions?

I know I can go inside python/Lib/site-packages and see what files and direc

12条回答
  •  感情败类
    2020-12-12 10:23

    My take:

    #!/usr/bin/env python3
    
    import pkg_resources
    
    dists = [str(d).replace(" ","==") for d in pkg_resources.working_set]
    for i in dists:
        print(i)
    

提交回复
热议问题