How to identify conda package dependents?

匿名 (未验证) 提交于 2019-12-03 03:05:02

问题:

For a given conda package, how to I list the packages that depend on it?

I recently installed anaconda on a university cluster that already had a version of MPI (openmpi). The mpich2 package and mpi4py packages installed with anaconda were fine for demos of mpi4py, but the mpi* compilers (mpicc, etc) were not compatable. So I conda remove'd mpich2 and mpi4py and used pip to install mpi4py using the local MPI install and compilers.

I had to dig around to find mpi4py's dependencies and then mpich2's dependents, for which I only identified mpi4py. Is there an "easy" way to find out what depends on mpich2?

回答1:

Searching the package cache will only show you the packages that you have downloaded already. For your case, this behavior is fine, but if you want to know every package that depends on a given package, a better way is to search the repodata of your channels. The repodata is cached in ~/anaconda/pkgs/cache, or you can navigate with your browser to http://repo.continuum.io/pkgs/free/ and click on repodata.json for the platform you use (for Binstar, go to, e.g., https://conda.binstar.org/asmeurer). Then search for the name of the package in the "depends" key.



回答2:

conda info will tell you the directory (or directories) where your package cache is located. These directories contain a unique directory for each package, and each package directory contains an info directory and a file called index.json. There is a requires field in each of these files that refers to a list of conda dependencies. So in short, you need to search these files for the package you're trying to remove.

For example, if anaconda's installed in my home directory, and therefore the package cache is ~/anaconda/pkgs, to find mpich2's dependents, I would:

grep mpich2 ~/anaconda/pkgs/*/info/index.json

You will see 2 lines for the anaconda package, because mpich2 is both in the aforementioned requires list and in a list called depends. You'll also see one line for each mpich2 package available, because there is also a name field for each package. Then you'll see one or more lines for each package that depends on, requires mpich2. My search produced only mpi4py.

Now I thought you could do a --dry-run remove, but it appears that remove does not remove dependents, so nothing special is listed.

If grep is unavailable, then I'm sure you could make a python script to do the same thing, using say the globmodule and maybe even json to do the searching.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!