zf = zipfile.ZipFile(output, 'w')
for mod in mf.modules.values():
    if not mod.__file__:
        continue
modfile = os.path.abspath(mod.__file__)
if os.path.commonprefix([cwd, modfile]) == cwd:
    zf.write(modfile, os.path.relpath(modfile))
zf.close()
if __name__ == '__main__':
    main(*sys.argv[1:])
Gather all Python modules used into one folder?