code: def save_pip(self, out_dir):
          
          try:
              import pkg_resources
  
              installed_packages = [d for d in iter(pkg_resources.working_set)]
              installed_packages_list = sorted(
                  ["%s==%s" % (i.key, i.version) for i in installed_packages]
              )
              with open(os.path.join(out_dir, 'requirements.txt'), 'w') as f:
                  f.write("\n".join(installed_packages_list))
          except Exception as e:
              logger.error("Error saving pip packages")
docs: Saves the current working set of pip packages to requirements.txt