Created
September 19, 2014 17:36
-
-
Save nderkach/2e55b1028bb99e1a678b to your computer and use it in GitHub Desktop.
Find missing python packages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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