#funcs import pip._internal as pip def from_pack(file): file = open(file) packages = set(file.read().split('\n')) - set(package.key for package in pip.get_installed_distributions()) file.close() for package in packages: pip.main(['install',package]) def to_pack(file): file = open(file,'w') s = '\n'.join(map(lambda p: p.key,pip.get_installed_distributions())) file.write(s) file.close() #arguments if __name__ == "__main__": import argparse parser = argparse.ArgumentParser() parser.add_argument("mode",metavar = "action",help="what you wanna do") parser.add_argument("path",metavar = "dir",help="fullpath to pack") args = parser.parse_args() if args.mode == "to_pack": to_pack(args.path) elif args.mode == "from_pack": from_pack(args.path)