Search code examples
pythonlinuxpiprpmpython-wheel

python + how to verify which python wheel or rpm installed that equivalent to import XXXX


in some python script we can see the import of some python modules as

import yum
import rpm
.
.
.

can we find exactly the rpm or wheel that actually installed the yum or the rpm ?

for example by pip list | grep yum

I not sure that I get the wheel that represent the "yum import"

and from rpm -qa | grep yum I get long list

so how to know the specific package that installed ? that related to import yum ?


Solution

  • $ strace python3 -c 'import rpm' 2>&1 |grep open
    ....
    openat(AT_FDCWD, "/usr/lib64/python3.11/site-packages/rpm/__pycache__/transaction.cpython-311.pyc", O_RDONLY|O_CLOEXEC) = 3
    openat(AT_FDCWD, "/proc/sys/crypto/fips_enabled", O_RDONLY) = 3
    $ rpm -qf /usr/lib64/python3.11/site-packages/rpm/__pycache__/transaction.cpython-311.pyc
    python3-rpm-4.18.1-3.fc38.x86_64
    

    If the rpm tells you

    file XXXX is not owned by any package
    

    then the file was not installed from rpm. So it likely comes from pip install.