In case of pip list, the pkg_resources library is used to access resource files for Python Libraries.
For this, a Working Set access the active distributions. From the docs, a working set
represents the distributions that are currently active on sys.path.
Thus, when calling an instance of WorkingSet, by default it will search for modules located on sys.path.
For example, when I run sys.path
['/opt/conda/lib/python37.zip',
'/opt/conda/lib/python3.7',
'/opt/conda/lib/python3.7/lib-dynload',
'',
'/opt/conda/lib/python3.7/site-packages',
'/opt/conda/lib/python3.7/site-packages/IPython/extensions'
]
These are the paths that will be used to search for installed packages. An example follows
import pkg_resources
# Define working set
working_set = pkg_resources.working_set
# Package, version and location
[d for d in working_set]
>>>
[zipp 3.1.0 (/opt/conda/lib/python3.7/site-packages),
zict 2.0.0 (/opt/conda/lib/python3.7/site-packages),
...,
attrs 19.3.0 (/opt/conda/lib/python3.7/site-packages),
async-generator 1.10 (/opt/conda/lib/python3.7/site-packages),
alembic 1.4.2 (/opt/conda/lib/python3.7/site-packages)]