code: def get_pkg_version(pkg_name, parse=False):
      
      import pkg_resources  # part of setuptools
      try:
          version = pkg_resources.require(pkg_name)[0].version
          return pkg_resources.parse_version(version) if parse else version
      except pkg_resources.DistributionNotFound:
          return None
docs: Verify and get installed python package version.
  
      :param pkg_name:    python package name
      :param parse: parse version number with pkg_resourc.parse_version -function
      :return: None if pkg is not installed,
      otherwise version as a string or parsed version when parse=True