Setup the environment on disk using virtualenv.
        Then, all of the requirements are installed into
        it using `pip install`.
347785
def _setup(self):
        
        log.info("Creating virtualenv for {0}".format(self.name))
        util.check_call([
            sys.executable,
            "-mvirtualenv",
            '--no-site-packages',
            "-p",
            self._executable,
            self._path])

        log.info("Installing requirements for {0}".format(self.name))
        self._install_requirements()
976281
def __setup(self):
        
        if not os.path.exists(self.__local_download_dir_warc):
            os.makedirs(self.__local_download_dir_warc)

        # make loggers quite
        configure_logging({"LOG_LEVEL": "ERROR"})
        logging.getLogger('requests').setLevel(logging.CRITICAL)
        logging.getLogger('readability').setLevel(logging.CRITICAL)
        logging.getLogger('PIL').setLevel(logging.CRITICAL)
        logging.getLogger('newspaper').setLevel(logging.CRITICAL)
        logging.getLogger('newsplease').setLevel(logging.CRITICAL)
        logging.getLogger('urllib3').setLevel(logging.CRITICAL)

        # set own logger
        logging.basicConfig(level=self.__log_level)
        self.__logger = logging.getLogger(__name__)
        self.__logger.setLevel(self.__log_level)
851396
def pip_install_requirements(requirements, constraints=None, **options):
    
    command = ["install"]

    available_options = ('proxy', 'src', 'log', )
    for option in parse_options(options, available_options):
        command.append(option)

    command.append("-r {0}".format(requirements))
    if constraints:
        command.append("-c {0}".format(constraints))
        log("Installing from file: {} with constraints {} "
            "and options: {}".format(requirements, constraints, command))
    else:
        log("Installing from file: {} with options: {}".format(requirements,
                                                               command))
    pip_execute(command)
829609
def install(python=PYTHON):
    """"""
    local(
        "LIBRARY_PATH={library_path} CPATH={include_path} {python} "
        "setup.py build".format(
            library_path=LIBRARY_PATH,
            include_path=INCLUDE_PATH,
            python=python,
        ))
    local("sudo {python} setup.py install".format(python=python))
1160560
def create(self):
        '''
        
        '''
        # require that the venv does not yet exist.
        if self.exists():
            raise Exception('Path already exists. Abort creation. venv={}'.format(self.venv))

        # create the venv dir
        run('mkdir -p {}'.format(self.venv))

        # create the virtual environment
        run('{virtualenv} {venv}'.format(virtualenv=self.virtualenv, venv=self.venv))
991788
def dir_cmd(argv):
    """"""
    env = parse_envname(argv, lambda : sys.exit('You must provide a valid virtualenv to target'))
    print(workon_home / env)
778940
def create_virtualenv(venv_dir, use_venv_module=True):
        

        if not use_venv_module:
            try:
                check_call(['virtualenv', venv_dir, '--no-site-packages'])
            except OSError:
                raise Exception('You probably dont have virtualenv installed: sudo apt-get install python-virtualenv')
        else:
            check_call([sys.executable or 'python', '-m', 'venv', venv_dir])
895763
def install_package(context):
    """"""

    if not context.dry_run and build_distributions(context):
        with util.mktmpdir() as tmp_dir:
            venv.create_venv(tmp_dir=tmp_dir)
            for distribution in Path('dist').files():
                try:
                    venv.install(distribution, tmp_dir)
                    log.info('Successfully installed %s', distribution)
                    if context.test_command and verification.run_test_command(context):
                        log.info(
                            'Successfully ran test command: %s', context.test_command
                        )
                except Exception as e:
                    raise Exception(
                        'Error installing distribution %s' % distribution, e
                    )
    else:
        log.info('Dry run, skipping installation')
1285395
def create_virtualenv(self):
        
        return task.create_virtualenv(self.target, self.datadir,
            self._preload_image(), self._get_container_name)
1346386
def install_package_to_venv(self):
        '''
        
        '''
        try:
            self.env.install(self.name, force=True, options=["--no-deps"])
        except (ve.PackageInstallationException,
                ve.VirtualenvReadonlyException):
            raise VirtualenvFailException(
                'Failed to install package to virtualenv')
        self.dirs_after_install.fill(self.temp_dir + '/venv/')
1361794
def do_init(
    dev=False,
    requirements=False,
    allow_global=False,
    ignore_pipfile=False,
    skip_lock=False,
    system=False,
    concurrent=True,
    deploy=False,
    pre=False,
    keep_outdated=False,
    requirements_dir=None,
    pypi_mirror=None,
):
    """"""
    from .environments import (
        PIPENV_VIRTUALENV, PIPENV_DEFAULT_PYTHON_VERSION, PIPENV_PYTHON, PIPENV_USE_SYSTEM
    )
    python = None
    if PIPENV_PYTHON is not None:
        python = PIPENV_PYTHON
    elif PIPENV_DEFAULT_PYTHON_VERSION is not None:
        python = PIPENV_DEFAULT_PYTHON_VERSION

    if not system and not PIPENV_USE_SYSTEM:
        if not project.virtualenv_exists:
            try:
                do_create_virtualenv(python=python, three=None, pypi_mirror=pypi_mirror)
            except KeyboardInterrupt:
                cleanup_virtualenv(bare=False)
                sys.exit(1)
    # Ensure the Pipfile exists.
    if not deploy:
        ensure_pipfile(system=system)
    if not requirements_dir:
        requirements_dir = vistir.path.create_tracked_tempdir(
            suffix="-requirements", prefix="pipenv-"
        )
    # Write out the lockfile if it doesn't exist, but not if the Pipfile is being ignored
    if (project.lockfile_exists and not ignore_pipfile) and not skip_lock:
        old_hash = project.get_lockfile_hash()
        new_hash = project.calculate_pipfile_hash()
        if new_hash != old_hash:
            if deploy:
                click.echo(
                    crayons.red(
                        "Your Pipfile.lock ({0}) is out of date. Expected: ({1}).".format(
                            old_hash[-6:], new_hash[-6:]
                        )
                    )
                )
                raise exceptions.DeployException
                sys.exit(1)
            elif (system or allow_global) and not (PIPENV_VIRTUALENV):
                click.echo(
                    crayons.red(fix_utf8(
                        "Pipfile.lock ({0}) out of date, but installation "
                        "uses {1}… re-building lockfile must happen in "
                        "isolation. Please rebuild lockfile in a virtualenv. "
                        "Continuing anyway…".format(
                            crayons.white(old_hash[-6:]), crayons.white("--system")
                        )),
                        bold=True,
                    ),
                    err=True,
                )
            else:
                if old_hash:
                    msg = fix_utf8("Pipfile.lock ({0}) out of date, updating to ({1})…")
                else:
                    msg = fix_utf8("Pipfile.lock is corrupted, replaced with ({1})…")
                click.echo(
                    crayons.red(msg.format(old_hash[-6:], new_hash[-6:]), bold=True),
                    err=True,
                )
                do_lock(
                    system=system,
                    pre=pre,
                    keep_outdated=keep_outdated,
                    write=True,
                    pypi_mirror=pypi_mirror,
                )
    # Write out the lockfile if it doesn't exist.
    if not project.lockfile_exists and not skip_lock:
        # Unless we're in a virtualenv not managed by pipenv, abort if we're
        # using the system's python.
        if (system or allow_global) and not (PIPENV_VIRTUALENV):
            raise exceptions.PipenvOptionsError(
                "--system",
                "--system is intended to be used for Pipfile installation, "
                "not installation of specific packages. Aborting.\n"
                "See also: --deploy flag."
            )
        else:
            click.echo(
                crayons.normal(fix_utf8("Pipfile.lock not found, creating…"), bold=True),
                err=True,
            )
            do_lock(
                system=system,
                pre=pre,
                keep_outdated=keep_outdated,
                write=True,
                pypi_mirror=pypi_mirror,
            )
    do_install_dependencies(
        dev=dev,
        requirements=requirements,
        allow_global=allow_global,
        skip_lock=skip_lock,
        concurrent=concurrent,
        requirements_dir=requirements_dir,
        pypi_mirror=pypi_mirror,
    )

    # Hint the user what to do to activate the virtualenv.
    if not allow_global and not deploy and "PIPENV_ACTIVE" not in os.environ:
        click.echo(
            "To activate this project's virtualenv, run {0}.\n"
            "Alternatively, run a command "
            "inside the virtualenv with {1}.".format(
                crayons.red("pipenv shell"), crayons.red("pipenv run")
            )
        )
210903
def do_create_virtualenv(python=None, site_packages=False, pypi_mirror=None):
    """"""

    click.echo(
        crayons.normal(fix_utf8("Creating a virtualenv for this project…"), bold=True), err=True
    )
    click.echo(
        u"Pipfile: {0}".format(crayons.red(project.pipfile_location, bold=True)),
        err=True,
    )

    # Default to using sys.executable, if Python wasn't provided.
    if not python:
        python = sys.executable
    click.echo(
        u"{0} {1} {3} {2}".format(
            crayons.normal("Using", bold=True),
            crayons.red(python, bold=True),
            crayons.normal(fix_utf8("to create virtualenv…"), bold=True),
            crayons.green("({0})".format(python_version(python))),
        ),
        err=True,
    )

    cmd = [
        vistir.compat.Path(sys.executable).absolute().as_posix(),
        "-m",
        "virtualenv",
        "--prompt=({0}) ".format(project.name),
        "--python={0}".format(python),
        project.get_location_for_virtualenv(),
    ]

    # Pass site-packages flag to virtualenv, if desired…
    if site_packages:
        click.echo(
            crayons.normal(fix_utf8("Making site-packages available…"), bold=True), err=True
        )
        cmd.append("--system-site-packages")

    if pypi_mirror:
        pip_config = {"PIP_INDEX_URL": vistir.misc.fs_str(pypi_mirror)}
    else:
        pip_config = {}

    # Actually create the virtualenv.
    nospin = environments.PIPENV_NOSPIN
    with create_spinner("Creating virtual environment...") as sp:
        c = vistir.misc.run(
            cmd, verbose=False, return_object=True, write_to_stdout=False,
            combine_stderr=False, block=True, nospin=True, env=pip_config,
        )
        click.echo(crayons.blue("{0}".format(c.out)), err=True)
        if c.returncode != 0:
            sp.fail(environments.PIPENV_SPINNER_FAIL_TEXT.format("Failed creating virtual environment"))
            error = c.err if environments.is_verbose() else exceptions.prettify_exc(c.err)
            raise exceptions.VirtualenvCreationException(
                extra=[crayons.red("{0}".format(error)),]
            )
        else:

            sp.green.ok(environments.PIPENV_SPINNER_OK_TEXT.format(u"Successfully created virtual environment!"))

    # Associate project directory with the environment.
    # This mimics Pew's "setproject".
    project_file_name = os.path.join(project.virtualenv_location, ".project")
    with open(project_file_name, "w") as f:
        f.write(vistir.misc.fs_str(project.project_directory))
    from .environment import Environment
    sources = project.pipfile_sources
    project._environment = Environment(
        prefix=project.get_location_for_virtualenv(),
        is_venv=True,
        sources=sources,
        pipfile=project.parsed_pipfile,
        project=project
    )
    project._environment.add_dist("pipenv")
    # Say where the virtualenv is.
    do_where(virtualenv=True, bare=False)
827529
def install_reqs(venv, repo_dest):
    """"""
    with dir_path(repo_dest):
        args = ['-r', 'requirements/compiled.txt']
        if not verbose:
            args.insert(0, '-q')
        subprocess.check_call([os.path.join(venv, 'bin', 'pip'), 'install'] +
                              args)
128094
def install():
    
    # Install system requirements
    sudo("apt-get update -y -q")
    apt("nginx libjpeg-dev python-dev python-setuptools git-core "
        "postgresql libpq-dev memcached supervisor python-pip")
    run("mkdir -p /home/%s/logs" % env.user)

    # Install Python requirements
    sudo("pip install -U pip virtualenv virtualenvwrapper mercurial")

    # Set up virtualenv
    run("mkdir -p %s" % env.venv_home)
    run("echo 'export WORKON_HOME=%s' >> /home/%s/.bashrc" % (env.venv_home,
                                                              env.user))
    run("echo 'source /usr/local/bin/virtualenvwrapper.sh' >> "
        "/home/%s/.bashrc" % env.user)
    print(green("Successfully set up git, mercurial, pip, virtualenv, "
                "supervisor, memcached.", bold=True))
775256
def install_dependencies(dependencies, verbose=False):
    """"""
    if not dependencies:
        return

    stdout = stderr = None if verbose else subprocess.DEVNULL
    with tempfile.TemporaryDirectory() as req_dir:
        req_file = Path(req_dir) / "requirements.txt"

        with open(req_file, "w") as f:
            for dependency in dependencies:
                f.write(f"{dependency}\n")

        pip = ["python3", "-m", "pip", "install", "-r", req_file]
        # Unless we are in a virtualenv, we need --user
        if sys.base_prefix == sys.prefix and not hasattr(sys, "real_prefix"):
            pip.append("--user")

        try:
            subprocess.check_call(pip, stdout=stdout, stderr=stderr)
        except subprocess.CalledProcessError:
            raise Error(_("failed to install dependencies"))

        # Reload sys.path, to find recently installed packages
        importlib.reload(site)
850739
def install_virtualenv_p3(root, python_version):
    
    import venv
    builder = venv.EnvBuilder(system_site_packages=False, clear=True, symlinks=False, upgrade=False)
    builder.create(root)
    ret_code = subprocess.call([VE_SCRIPT, PROJECT_ROOT, root, python_version])
    sys.exit(ret_code)
930457
def create_environment(home_dir, site_packages=True, clear=False,
                       unzip_setuptools=False, use_distribute=False):
    
    home_dir, lib_dir, inc_dir, bin_dir = path_locations(home_dir)

    py_executable = os.path.abspath(install_python(
        home_dir, lib_dir, inc_dir, bin_dir,
        site_packages=site_packages, clear=clear))

    install_distutils(lib_dir, home_dir)

    if use_distribute or os.environ.get('VIRTUALENV_USE_DISTRIBUTE'):
        install_distribute(py_executable, unzip=unzip_setuptools)
    else:
        install_setuptools(py_executable, unzip=unzip_setuptools)

    install_pip(py_executable)

    install_activate(home_dir, bin_dir)