def import_vboxapi():
    """This import is designed to help when loading vboxapi inside of
    alternative Python environments (virtualenvs etc).

    :rtype: vboxapi module
    """
    try:
        import vboxapi
    except ImportError:
        system = platform.system()
        py_mm_ver = sys.version_info[:2]
        py_major = sys.version_info[0]
        packages = ['vboxapi']

        if system == 'Windows':
            packages.extend(['win32com', 'win32', 'win32api', 'pywintypes', 'win32comext'])
            search = ['C:\\Python%s%s\\Lib\\site-packages' % py_mm_ver,
                      'C:\\Python%s%s\\Lib\\site-packages\\win32' % py_mm_ver,
                      'C:\\Python%s%s\\Lib\\site-packages\\win32\\lib' % py_mm_ver,
                      'C:\\Program Files\\Oracle\\VirtualBox\\sdk\\install',
                      'C:\\Program Files (x86)\\Oracle\\VirtualBox\\sdk\\install']

            for x in ['', py_major]:
                search.extend(['C:\\Anaconda%s\\Lib\\site-packages' % x,
                               'C:\\Anaconda%s\\Lib\\site-packages\\win32' % x,
                               'C:\\Anaconda%s\\Lib\\site-packages\\win32\\lib' % x])

        elif system == 'Linux':
            search = ['/usr/lib/python%s.%s/dist-packages' % py_mm_ver,
                      '/usr/lib/python%s.%s/site-packages' % py_mm_ver,
                      '/usr/share/pyshared']

        elif system == 'Darwin':
            search = ['/Library/Python/%s.%s/site-packages' % py_mm_ver]
        else:
            # No idea where to look...
            search = []

        # Generates a common prefix from sys.executable in the
        # case that vboxapi is installed in a virtualenv.
        # This will also help with when we don't know where
        # to search because of an unknown platform.
        # These paths also help if the system Python is installed
        # in a non-standard location.
        #
        # NOTE: We don't have to worry if these directories don't
        # exist as they're checked below.
        prefix = os.path.dirname(os.path.dirname(sys.executable))
        search.extend([os.path.join(prefix, 'Lib', 'site-packages'),
                       os.path.join(prefix, 'Lib', 'site-packages', 'win32'),
                       os.path.join(prefix, 'Lib', 'site-packages', 'win32', 'lib'),
                       os.path.join(prefix, 'lib', 'site-packages'),
                       os.path.join(prefix, 'lib', 'dist-packages')])

        packages = set(packages)
        original_path = copy.copy(sys.path)
        for path in search:
            if not os.path.isdir(path):
                continue
            listing = set([os.path.splitext(f)[0] for f in os.listdir(path)])
            if packages.intersection(listing):
                sys.path.append(path)
            packages -= listing
            if not packages:
                break
        else:
            # After search each path we still failed to find
            # the required set of packages.
            raise
        import vboxapi
        try:
            yield vboxapi
        finally:
            sys.path = original_path
    else:
        yield vboxapi
This import is designed to help when loading vboxapi inside of
    alternative Python environments (virtualenvs etc).

    :rtype: vboxapi module