How to identify conda package dependents?

前端 未结 6 2117
被撕碎了的回忆
被撕碎了的回忆 2020-12-25 11:29

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

I recently installed anaconda on a university cluster that al

6条回答
  •  无人及你
    2020-12-25 12:18

    Based on Yann's answer, code diving in conda core and reading this I came up with the following script to get a reverse-dependency graph of all cached channels:

    import glob
    import json
    import os
    
    from collections import defaultdict
    
    info = json.load(os.popen('conda info --json'))
    
    print('Loading channels...')
    channels = [
        json.load(open(repodata))
        for pkg_dir in info['pkgs_dirs']
        for repodata in glob.glob(os.path.join(pkg_dir, 'cache', '*.json'))
    ]
    print('Done')
    
    rdeps = defaultdict(set)
    
    for c in channels:
        for k, v in c['packages'].items():
            package = '-'.join(k.split('-')[:-2])
            for dep in v['depends']:
                dependant = dep.split()[0]
                rdeps[dependant].add((package, c['_url']))
    

    Now you can get the reverse dependencies of a specific package:

    >>> print(rdeps['mpich2'])
    set()
    

    Well, right now nothing depends on it anymore... But if you run it in ipython or Jupyter, you can then quickly query the reverse dependencies, e.g.:

    >>> print(rdeps['aiosqlite'])
    {('databases', 'https://conda.anaconda.org/conda-forge/linux-64')}
    

    You get the package name (without versions, of which there may be many), and the channel URL (which can show you, if it's pkgs/main/(arch) or conda-forge etc.

提交回复
热议问题