def pip_install_to_target(path, requirements=None, local_package=None):
packages = []<EOL>if not requirements:<EOL><INDENT>print('<STR_LIT>')<EOL>pkgStr = subprocess.check_output([sys.executable, '<STR_LIT>', '<STR_LIT>', '<STR_LIT>'])<EOL>packages.extend(pkgStr.decode('<STR_LIT:utf-8>').splitlines())<EOL><DEDENT>else:<EOL><INDENT>if os.path.exists(requirements):<EOL><INDENT>print('<STR_LIT>')<EOL>data = read(requirements)<EOL>packages.extend(data.splitlines())<EOL><DEDENT><DEDENT>if not packages:<EOL><INDENT>print('<STR_LIT>')<EOL><DEDENT>if local_package is not None:<EOL><INDENT>if not isinstance(local_package, (list, tuple)):<EOL><INDENT>local_package = [local_package]<EOL><DEDENT>for l_package in local_package:<EOL><INDENT>packages.append(l_package)<EOL><DEDENT><DEDENT>_install_packages(path, packages)<EOL>
For a given active virtualenv, gather all installed pip packages then
    copy (re-install) them to the path provided.

    :param str path:
        Path to copy installed pip packages to.
    :param str requirements:
        If set, only the packages in the supplied requirements file are
        installed.
        If not set then installs all packages found via pip freeze.
    :param str local_package:
        The path to a local package with should be included in the deploy as
        well (and/or is not available on PyPi)