os.chdir(os.path.dirname(setup_file))
exec(compile(open(os.path.basename(setup_file)).read(), os.path.basename(setup_file), 'exec'))
cat = lambda *seq: sum((i for i in seq if i is not None), [])
pkgs = set(package.split('.')[0] for package in cat(dist.packages, dist.
    py_modules, [m.name for m in cat(dist.ext_modules)], [m.name for m in
    cat(dist.ext_package)]))
print('\n'.join(pkgs))
Как найти «импортное имя» любого пакета в Python?