[英]Where does pip and conda keep the list of installed packages so that they know who installed what?
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.我在我的conda
环境中做了一些pip install
,似乎conda
和pip
遵循 python 约定,通过将包安装到site-packages
文件夹中。
When I use pip list
and conda list
, it seems they did a nice book keeping of who installed which packages.当我使用pip list
和conda list
,他们似乎很好地记录了谁安装了哪些软件包。 Question is, where are those two installation lists stored, on Linux?问题是,这两个安装列表在 Linux 上存储在哪里?
In case of pip list
, the pkg_resources library is used to access resource files for Python Libraries.在pip list
情况下, pkg_resources库用于访问 Python 库的资源文件。
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.表示当前在 sys.path 上处于活动状态的发行版。
Thus, when calling an instance of WorkingSet
, by default it will search for modules located on sys.path
.因此,当调用WorkingSet
的实例时,默认情况下它将搜索位于sys.path
上的模块。
For example, when I run sys.path
例如,当我运行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)]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.