Get actual package references from an iterable of package names
    :param packages: iterable of package names
    :type packages: iter of basestr
    :return: set of package references
    :rtype: set

def _import_packages(packages, optional=None):
    """
    Get actual package references from an iterable of package names
    :param packages: iterable of package names
    :type packages: iter of basestr
    :return: set of package references
    :rtype: set
    """
    if not optional:
        optional = []

    package_references = set()

    # Check all reqiured packages
    failures = set()
    for package_name in packages:
        try:
            package_reference = __import__(package_name, globals(), locals(), [], 0)
            package_references.add(package_reference)
        except ImportError:
            failures.add(package_name)

    # Report aggregated list of import failures (save a developer time when building a new frozen environment)
    if failures:
        raise ImportError(u"Unable to find required packages: {0}".format(u", ".join(failures)))

    # Check all optional packages (and warn if some aren't found)
    failures = set()
    for package_name in optional:
        try:
            package_reference = __import__(package_name, globals(), locals(), [], 0)
            package_references.add(package_reference)
        except ImportError:
            failures.add(package_name)

    # Warn user which optional packages weren't found
    for failure in failures:
        warn(ImportWarning(u"Unable to import {0}".format(failure)))

    return package_references