如何查找已安装的多个软件包?

如何查找已安装的多个软件包?

我刚刚发现我已经安装了两者gcc-10gcc-11并且已经安装了apt purge gcc-10 && apt autoremove)。

我想知道我可能还安装了哪些多个版本的其他软件包?

PS. 似乎gcc-12也存在,但apt install gcc-12 && apt purge gcc-11由于unmet dependencies)而失败

答案1

以下是我最终使用的方法:

import subprocess as sp

versioned = {}
with sp.Popen(["apt","list","--installed"], encoding="ascii",
              stdout=sp.PIPE, stderr=sp.STDOUT) as pipe:
    for pack in pipe.stdout:
        if "/" not in pack:
            print(pack)
            continue
        name = pack.split("/",1)[0]
        name_ver = name.rsplit("-",1)
        if len(name_ver) == 2 and name_ver[1].isdigit():
            versioned.setdefault(name_ver[0],set()).add(name_ver[1])

print(f"found {len(versioned):,d} versioned packages")
versioned = {n:v for n,v in versioned.items() if len(v) > 1}
print(f"found {len(versioned):,d} packages with multiple versions:\n{versioned}")

打印

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.



Listing...

found 240 versioned packages
found 3 packages with multiple versions:
{'cpp': {'12', '11'}, 'g++': {'12', '11'}, 'gcc': {'12', '11'}}

相关内容