Skip to content

Instantly share code, notes, and snippets.

@littmus
Created May 6, 2015 13:44
Show Gist options
  • Save littmus/5aa370b1de8e9ca35c33 to your computer and use it in GitHub Desktop.
Save littmus/5aa370b1de8e9ca35c33 to your computer and use it in GitHub Desktop.
compare
import os
from distutils.sysconfig import get_python_lib
from pip import get_installed_distributions
def get_locally_installed_packages():
path = get_python_lib()
packages = {}
for root, dirs, files in os.walk(path):
for item in files:
if "top_level" in item:
with open(os.path.join(root, item), "r") as f:
package = root.split("/")[-1].split("-")
package_import = f.read().strip().split("\n")
package_import_name = ""
for item in package_import:
if item not in ["tests", "_tests"]:
package_import_name = item
break
if package_import_name == "":
logging.debug(
'Could not determine import name for package ' + package_import)
else:
packages[package_import_name] = {
'version': package[1].replace(".dist", ""),
'name': package[0]
}
return packages
a=get_locally_installed_packages()
b=get_installed_distributions()
print len(a), sorted(a.keys())
print len(b), sorted([p.project_name for p in b])
print os.popen('pip list').read()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment