Different list of installed packages sing 'pip list' and 'pip.get_installed_distributions()'

后端 未结 1 336
Happy的楠姐
Happy的楠姐 2021-01-28 17:31

What is the difference between the command:

$ pip list

that I can run in a command line, and:

import pip
pip.get_installed_dist         


        
1条回答
  •  一整个雨季
    2021-01-28 17:52

    According to the definition of pip.get_installed_distributions() from the source code -

    def get_installed_distributions(local_only=True,
                                    skip=stdlib_pkgs,
                                    include_editables=True,
                                    editables_only=False,
                                    user_only=False):
    

    This is run with local_only set as True by default , whereas when you do pip list , it will show all packages local as well as globals, which is what may be happenning in your case and causing you to see much more package installed (both locally as well as globally).

    Try running pip list --local to get only locally installed packages

    or

    pip.get_installed_distributions(local_only=False)
    

    to get global packages as well.

    0 讨论(0)
提交回复
热议问题