Where does pip and conda keep the list of installed packages so that they know who installed what?

Viewed 371

I did some pip install in my conda environment, and it seems that both conda and pip follow the python convention, by installing packages into the site-packages folder.

When I use pip list and conda list, it seems they did a nice book keeping of who installed which packages. Question is, where are those two installation lists stored, on Linux?

1 Answers

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)]
Related