code: def merged_packages(env_packages, names):
      
      combined_packages = sorted(itertools.chain.from_iterable(
          env_packages[name].items()
          for name in names
      ))
      result = {}
      errors = set()
      for name, version in combined_packages:
          if name in result:
              if result[name] != version:
                  errors.add((name, version, result[name]))
          else:
              result[name] = version
      if errors:
          for error in sorted(errors):
              logger.error(
                  "Package %s was resolved to different "
                  "versions in different environments: %s and %s",
                  error[0], error[1], error[2],
              )
          raise RuntimeError(
              "Please add constraints for the package version listed above"
          )
      return result
docs: Return union set of environment packages with given names
  
      >>> sorted(merged_packages(
      ...     {
      ...         'a': {'x': 1, 'y': 2},
      ...         'b': {'y': 2, 'z': 3},
      ...         'c': {'z': 3, 'w': 4}
      ...     },
      ...     ['a', 'b']
      ... ).items())
      [('x', 1), ('y', 2), ('z', 3)]