def setup_virtualenvs(recreate_virtualenvs=False):
    """
    Setup Python virtual environments for all the registered or the provided pack.
    """

    LOG.info("=========================================================")
    LOG.info("########### Setting up virtual environments #############")
    LOG.info("=========================================================")
    pack_dir = cfg.CONF.register.pack
    fail_on_failure = not cfg.CONF.register.no_fail_on_failure

    registrar = ResourceRegistrar()

    if pack_dir:
        pack_name = os.path.basename(pack_dir)
        pack_names = [pack_name]

        # 1. Register pack
        registrar.register_pack(pack_name=pack_name, pack_dir=pack_dir)
    else:
        # 1. Register pack
        base_dirs = content_utils.get_packs_base_paths()
        registrar.register_packs(base_dirs=base_dirs)

        # 2. Retrieve available packs (aka packs which have been registered)
        pack_names = registrar.get_registered_packs()

    if recreate_virtualenvs:
        """
        update = False:
        this is more than an update of an existing virtualenv
        the virtualenv itself will be removed & recreated
        this is i.e. useful for updates to a newer Python release
        """
        update = False
    else:
        """
        update = True:
        only dependencies inside the virtualenv will be updated
        """
        update = True

    setup_count = 0
    for pack_name in pack_names:
        try:
            setup_pack_virtualenv(pack_name=pack_name, update=update, logger=LOG)
        except Exception as e:
            exc_info = not fail_on_failure
            LOG.warning(
                'Failed to setup virtualenv for pack "%s": %s',
                pack_name,
                e,
                exc_info=exc_info,
            )

            if fail_on_failure:
                raise e
        else:
            setup_count += 1

    LOG.info("Setup virtualenv for %s pack(s)." % (setup_count))

    Setup Python virtual environments for all the registered or the provided pack.
    
st2common/st2common/content/bootstrap.py