Skip to content

Instantly share code, notes, and snippets.

@nderkach
Created September 19, 2014 17:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nderkach/2e55b1028bb99e1a678b to your computer and use it in GitHub Desktop.
Save nderkach/2e55b1028bb99e1a678b to your computer and use it in GitHub Desktop.
Find missing python packages
#!/usr/bin/env python
import os
import importlib
for fn in os.listdir():
if fn.endswith(".py"):
with open(fn, 'r') as f:
for line in f:
if "import" in line:
if "from" in line:
modulelist = line.strip().split("from")[1].split("import")[0].strip()
else:
modulelist = line.strip().split("import")[1].strip()
print(modulelist)
for module in modulelist.split(","):
try:
m = module.strip()
importlib.import_module(m)
except Exception as e:
print(m, "not installed")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment