I want to know which python packages are installed via pip and which are installed via rpm.
I run outside any virtualenv, and want to know if there are some packages installed via pip.
Background: Our policy is to use RPM at "root level". I want to find places where the policy was broken.
If you want to list all the Python packages installed in an environment, pip list command is what you are looking for. The command will return all the packages installed, along with their specific version and location.
As I said above, running pip freeze gives you a list of all currently installed dependencies, but that does mean all of them.
How about turn the question around slightly, and just check what belongs to rpms and what doesn't. Try:
import os, sys, subprocess, glob
def type_printed(pth, rpm_dirs=False):
if not os.path.exists(pth):
print(pth + ' -- does not exist')
return True
FNULL = open(os.devnull, 'w')
if rpm_dirs or not os.path.isdir(pth):
rc = subprocess.call(['rpm', '-qf', pth], stdout=FNULL, stderr=subprocess.STDOUT)
if rc == 0:
print(pth + ' -- IS RPM')
return True
print(pth + ' -- NOT an RPM')
return True
return False
for pth in sys.path:
if type_printed(pth):
continue
contents = glob.glob(pth + '/*')
for subpth in contents:
if type_printed(subpth, rpm_dirs=True):
continue
print(subpth + ' -- nothing could be determined for sure')
And pipe the output through something like
grep -e '-- NOT' -e '-- nothing could be determined'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With