code: def package_config():
      
      p = subprocess.Popen(['pkg-config', '--exists', '--atleast-version={}'.format(_TESSERACT_MIN_VERSION),
                            '--print-errors', 'tesseract'],
                           stderr=subprocess.PIPE)
      _, error = p.communicate()
      if p.returncode != 0:
          raise Exception(error)
      p = subprocess.Popen(['pkg-config', '--libs', '--cflags', 'tesseract'], stdout=subprocess.PIPE)
      output, _ = p.communicate()
      flags = _read_string(output).strip().split()
      p = subprocess.Popen(['pkg-config', '--libs', '--cflags', 'lept'], stdout=subprocess.PIPE)
      output, _ = p.communicate()
      flags2 = _read_string(output).strip().split()
      options = {'-L': 'library_dirs',
                 '-I': 'include_dirs',
                 '-l': 'libraries'}
      config = {}
      import itertools
      for f in itertools.chain(flags, flags2):
          try:
              opt = options[f[:2]]
          except KeyError:
              continue
          val = f[2:]
          if opt == 'include_dirs' and psplit(val)[1].strip(os.sep) in ('leptonica', 'tesseract'):
              val = dirname(val)
          config.setdefault(opt, set()).add(val)
      config = {k: list(v) for k, v in config.items()}
      p = subprocess.Popen(['pkg-config', '--modversion', 'tesseract'], stdout=subprocess.PIPE)
      version, _ = p.communicate()
      version = _read_string(version).strip()
      _LOGGER.info("Supporting tesseract v{}".format(version))
      config['cython_compile_time_env'] = {'TESSERACT_VERSION': version_to_int(version)}
      _LOGGER.info("Configs from pkg-config: {}".format(config))
      return config
docs: Use pkg-config to get library build parameters and tesseract version.