def inject_st2_pth_into_virtualenv(virtualenv_path: str, logger: Logger = None) -> None:
    """
    Add a .pth file to the pack virtualenv that loads any .pth files from the st2 virtualenv.

    If the primary st2 venv (typically /opt/stackstorm/st2) contains any .pth files,
    the pack's virtualenv would not load them because that directory is on the PYTHONPATH,
    but it is not a "sites" directory that the "site" module will try to load from.
    To work around this, we add an .pth file that registers the st2 venv's
    site-packages directory as a "sites" directory.

    Sites dirs get loaded from (in order): venv, [user site-packages,] system site-packages.
    After the sites dirs are loaded (including loading their .pth files), sitecustomize gets
    imported. We do not use sitecustomize because we need the st2 venv's .pth files to load
    after the pack venv and before system site-packages. So, we use a .pth file that loads
    as late as possible.
    """
    logger = logger or LOG
    if not is_in_virtualenv():
        # If this is installed in the system-packages directory, then
        # its site-packages directory should already be included.
        logger.debug("Not in a virtualenv; Skipping st2 .pth injection.")
        return

    parent_site_packages_dir = get_site_packages_dir()

    contents = dedent(
        # The .pth format requires that any code be on one line.
        # https://docs.python.org/3/library/site.html
        # The line gets passed through exec() which uses the scope of site.addpackage()
        f"""\
        # This file is auto-generated by StackStorm.
        import sys; addsitedir('{parent_site_packages_dir}', known_paths)
        """
        # TODO: Maybe use this to adjust PATH and PYTHONPATH as well.
        #       This could replace manipulations in python_runner and sensor process_container:
        #       env["PATH"] = st2common.util.sandboxing.get_sandbox_path(...)
        #       env["PYTHONPATH"] = st2common.util.sandboxing.get_sandbox_python_path*(...)
    )

    # .pth filenames are sorted() before loading, so use many "z"s to ensure
    # any st2 virtualenv .pth files get loaded after .pth files in the pack's virtualenv.
    pth_file = (
        Path(get_virtualenv_lib_path(virtualenv_path))
        / "site-packages"
        / "zzzzzzzzzz__st2__.pth"
    )
    pth_file.write_text(contents)

    Add a .pth file to the pack virtualenv that loads any .pth files from the st2 virtualenv.

    If the primary st2 venv (typically /opt/stackstorm/st2) contains any .pth files,
    the pack's virtualenv would not load them because that directory is on the PYTHONPATH,
    but it is not a "sites" directory that the "site" module will try to load from.
    To work around this, we add an .pth file that registers the st2 venv's
    site-packages directory as a "sites" directory.

    Sites dirs get loaded from (in order): venv, [user site-packages,] system site-packages.
    After the sites dirs are loaded (including loading their .pth files), sitecustomize gets
    imported. We do not use sitecustomize because we need the st2 venv's .pth files to load
    after the pack venv and before system site-packages. So, we use a .pth file that loads
    as late as possible.
    
st2common/st2common/util/virtualenvs.py