code: def check_package_exists(package, lib_dir):
      
      try:
          req = pkg_resources.Requirement.parse(package)
      except ValueError:
          # This is a zip file
          req = pkg_resources.Requirement.parse(urlparse(package).fragment)
  
      # Check packages from lib dir
      if lib_dir is not None:
          if any(dist in req for dist in
                 pkg_resources.find_distributions(lib_dir)):
              return True
  
      # Check packages from global + virtual environment
      # pylint: disable=not-an-iterable
      return any(dist in req for dist in pkg_resources.working_set)
docs: Check if a package is installed globally or in lib_dir.
  
      Returns True when the requirement is met.
      Returns False when the package is not installed or doesn't meet req.