Reputation: 42389
What is the difference between the command:
$ pip list
that I can run in a command line, and:
import pip
pip.get_installed_distributions()
which I run within a python
environment.
Why do they return a different list of installed packages?
Upvotes: 0
Views: 1176
Reputation: 90979
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.
Upvotes: 2