[英]What's the equivalent for "rpm -qf <FILE>" with the Python rpm library?
# rpm -qf /usr/lib64/python3.7/site-packages/six.py
python3-six-1.12.0-r0
How do I use Python to query which package the file belongs to?如何使用Python查询文件属于哪个包?
I was going to say Google it, but it actually doesn't return results. 我本来是要说Google的,但实际上并没有返回结果。 I guess it's a very unorthodox way of approaching the problem/asking the question. 我想这是解决问题/提出问题的非常不合常规的方法。
Python default uses pip
to install packages. Python默认使用pip
安装软件包。 Find the documentation here 在此处找到文档
Another option is easy_install
, and many recommend doing it through conda
which requires Anaconda and requires more set-up but manages a nice controlled Python environment to manage versions within. 另一个选项是easy_install
,许多人建议通过conda
,这需要Anaconda并需要更多设置,但需要管理一个不错的受控Python环境来管理其中的版本。
Google should show you those. Google应该向您显示这些内容。
I've not found a direct call to the rpm database that gives in return the package providing a given file, so the better solution I've right now is the following:我还没有找到对 rpm 数据库的直接调用,该调用返回提供给定文件的包,所以我现在更好的解决方案如下:
#!/usr/bin/env python3
import rpm
CHECK_FILE = "/usr/lib/python3.9/site-packages/six.py"
ts = rpm.TransactionSet()
mi = ts.dbMatch()
for h in mi:
files = h['FILENAMES']
if CHECK_FILE in files:
print("{}-{}-{}".format(h['name'], h['version'], h['release']))
break
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.