Find which version of package is installed with pip

前端 未结 15 2155
死守一世寂寞
死守一世寂寞 2020-12-04 04:43

Using pip, is it possible to figure out which version of a package is currently installed?

I know about pip install XYZ --upgrade but I am wondering if

15条回答
  •  醉酒成梦
    2020-12-04 05:15

    import pkg_resources
    packages = [dist.project_name for dist in pkg_resources.working_set]
    try:
       for count, item in enumerate(packages):
          print(item, pkg_resources.get_distribution(item).version)
    except:
        pass here
    

    The indentations might not be perfect. The reason I am using a Try- Except block is that few library names will throw errors because of parsing the library names to process the versions. even though packages variable will contain all the libraries install in your environment.

提交回复
热议问题