code: def key_from_req(req):
      
      if hasattr(req, "key"):
          # from pkg_resources, such as installed dists for pip-sync
          key = req.key
      else:
          # from packaging, such as install requirements from requirements.txt
          key = req.name
  
      key = key.replace("_", "-").lower()
      return key
docs: Get an all-lowercase version of the requirement's name.