creates a new virtualenv in venv_dir

        By default, the built-in venv module is used.
        On older versions of python, you may set use_venv_module to False to use virtualenv
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])
131662
def _build_new_virtualenv(self):
        ''''''
        if self._virtualenv is None:
            # virtualenv was "None" which means "do default"
            self._pkg_venv = os.path.join(self._temp_workspace, 'venv')
            self._venv_pip = 'bin/pip'
            if sys.platform == 'win32' or sys.platform == 'cygwin':
                self._venv_pip = 'Scripts\pip.exe'

            python_exe = self._python_executable()

            proc = Popen(["virtualenv", "-p", python_exe,
                          self._pkg_venv], stdout=PIPE, stderr=PIPE)
            stdout, stderr = proc.communicate()
            LOG.debug("Virtualenv stdout: %s" % stdout)
            LOG.debug("Virtualenv stderr: %s" % stderr)

            if proc.returncode is not 0:
                raise Exception('virtualenv returned unsuccessfully')

        else:
            raise Exception('cannot build a new virtualenv when asked to omit')
6151
def clean_virtualenv(self):
        
        self.user_run_script(
            script=scripts.get_script_path('clean_virtualenv.sh'),
            args=[],
            rw_venv=True,
            )
539590
def create_virtualenv(venv=VENV, install_pip=False):
    
    print 'Creating venv...',

    install = ['virtualenv', '-q', venv]
    run_command(install)

    print 'done.'
    print 'Installing pip in virtualenv...',
    if install_pip and \
            not run_command(['tools/with_venv.sh', 'easy_install',
                             'pip>1.0']):
        die("Failed to install pip.")
    print 'done.'
1193119
def create(self):
        
        if self.path is not None:
            logger.debug(
                "Skipped creation of temporary directory: {}".format(self.path)
            )
            return
        # We realpath here because some systems have their default tmpdir
        # symlinked to another directory.  This tends to confuse build
        # scripts, so we canonicalize the path by traversing potential
        # symlinks here.
        self.path = os.path.realpath(
            tempfile.mkdtemp(prefix="pip-{}-".format(self.kind))
        )
        self._register_finalizer()
        logger.debug("Created temporary directory: {}".format(self.path))
893406
def is_venv():
    
    dir_path = os.path.dirname(SRC)
    is_venv_flag = True

    if SYS_NAME == "Windows":
        executable_list = ["activate", "pip.exe", "python.exe"]
    elif SYS_NAME in ["Darwin", "Linux"]:
        executable_list = ["activate", "pip", "python"]

    for executable in executable_list:
        path = os.path.join(dir_path, BIN_SCRIPTS, executable)
        if not os.path.exists(path):
            is_venv_flag = False

    return is_venv_flag
1145946
def make_virtualenv(env):
    
    if find_executable("virtualenv") is not None:
        cmd = ["virtualenv"] + [env]
        subprocess.check_call(cmd)
    else:
        # Otherwise, download virtualenv from pypi
        path = urlretrieve(VENV_URL)[0]
        subprocess.check_call(["tar", "xzf", path])
        subprocess.check_call(
            [sys.executable, "virtualenv-%s/virtualenv.py" % VENV_VERSION, env]
        )
        os.unlink(path)
        shutil.rmtree("virtualenv-%s" % VENV_VERSION)
436132
def setup_benchbuild():
    
    LOG.debug("Setting up Benchbuild...")

    venv_dir = local.path("/benchbuild")
    prefixes = CFG["container"]["prefixes"].value
    prefixes.append(venv_dir)
    CFG["container"]["prefixes"] = prefixes

    src_dir = str(CFG["source_dir"])
    have_src = src_dir is not None
    if have_src:
        __mount_source(src_dir)

    benchbuild = find_benchbuild()
    if benchbuild and not requires_update(benchbuild):
        if have_src:
            __upgrade_from_source(venv_dir, with_deps=False)
        return

    setup_virtualenv(venv_dir)
    if have_src:
        __upgrade_from_source(venv_dir)
    else:
        __upgrade_from_pip(venv_dir)
107139
def get_virtualenv_path(ve_base, ve_name):
    
    if not ve_base:
        raise exceptions.NoVirtualenvsDirectory(
            "could not figure out a virtualenvs directory. "
            "make sure $HOME is set, or $WORKON_HOME,"
            " or set virtualenvs=something in your .vexrc")

    # Using this requires get_ve_base to pass through nonexistent dirs
    if not os.path.exists(ve_base):
        message = (
            "virtualenvs directory {0!r} not found. "
            "Create it or use vex --make to get started."
        ).format(ve_base)
        raise exceptions.NoVirtualenvsDirectory(message)

    if not ve_name:
        raise exceptions.InvalidVirtualenv("no virtualenv name")

    # n.b.: if ve_name is absolute, ve_base is discarded by os.path.join,
    # and an absolute path will be accepted as first arg.
    # So we check if they gave an absolute path as ve_name.
    # But we don't want this error if $PWD == $WORKON_HOME,
    # in which case 'foo' is a valid relative path to virtualenv foo.
    ve_path = os.path.join(ve_base, ve_name)
    if ve_path == ve_name and os.path.basename(ve_name) != ve_name:
        raise exceptions.InvalidVirtualenv(
            'To run in a virtualenv by its path, '
            'use "vex --path {0}"'.format(ve_path))

    ve_path = os.path.abspath(ve_path)
    if not os.path.exists(ve_path):
        raise exceptions.InvalidVirtualenv(
            "no virtualenv found at {0!r}.".format(ve_path))
    return ve_path
370015
def venv_update(
        venv=DEFAULT_OPTION_VALUES['venv='],
        install=DEFAULT_OPTION_VALUES['install='],
        pip_command=DEFAULT_OPTION_VALUES['pip-command='],
        bootstrap_deps=DEFAULT_OPTION_VALUES['bootstrap-deps='],
):
    

    # SMELL: mutable argument as return value
    class return_values(object):
        venv_path = None

    try:
        ensure_virtualenv(venv, return_values)
        if return_values.venv_path is None:
            return
        # invariant: the final virtualenv exists, with the right python version
        raise_on_failure(lambda: pip_faster(return_values.venv_path, pip_command, install, bootstrap_deps))
    except BaseException:
        mark_venv_invalid(return_values.venv_path)
        raise
    else:
        mark_venv_valid(return_values.venv_path)
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()
626630
def install_virtualenv_p2(root, python_version):
    
    try:
        import virtualenv
    except ImportError:
        sys.stdout.write('Installing virtualenv into global interpreter \n')
        ret_code = subprocess.call([VE_GLOBAL_SCRIPT, PROJECT_ROOT])
        sys.stdout.write('Installation finished with code {0}. Re-run ./launch.py install \n'.format(ret_code))
        sys.exit(ret_code)

    if path.exists(root):
        shutil.rmtree(root)
    virtualenv.logger = virtualenv.Logger(consumers=[])
    virtualenv.create_environment(root, site_packages=False)
    ret_code = subprocess.call([VE_SCRIPT, PROJECT_ROOT, root, python_version])
    sys.exit(ret_code)
192480
def find_linux_venv_py_version():
    
    available_python_version = [
        "python2.6",
        "python2.7",
        "python3.3",
        "python3.4",
        "python3.5",
        "python3.6",
    ]
    dir_path = os.path.dirname(SRC)
    for basename in os.listdir(os.path.join(dir_path, BIN_SCRIPTS)):
        for python_version in available_python_version:
            if python_version in basename:
                return python_version
    raise Exception("Can't find virtualenv python version!")
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)
904360
def create(cls, env=None, args=None):
    
    env = {k: v for k, v in (os.environ if env is None else env).items()
           if k.startswith('PANTS_')}
    args = tuple(sys.argv if args is None else args)

    flags = set()
    short_flags = set()

    def filecontent_for(path):
      return FileContent(ensure_text(path), read_file(path, binary_mode=True))

    def capture_the_flags(*args, **kwargs):
      for arg in args:
        flags.add(arg)
        if len(arg) == 2:
          short_flags.add(arg)
        elif kwargs.get('type') == bool:
          flags.add('--no-{}'.format(arg[2:]))

    GlobalOptionsRegistrar.register_bootstrap_options(capture_the_flags)

    def is_bootstrap_option(arg):
      components = arg.split('=', 1)
      if components[0] in flags:
        return True
      for flag in short_flags:
        if arg.startswith(flag):
          return True
      return False

    # Take just the bootstrap args, so we don't choke on other global-scope args on the cmd line.
    # Stop before '--' since args after that are pass-through and may have duplicate names to our
    # bootstrap options.
    bargs = tuple(filter(is_bootstrap_option, itertools.takewhile(lambda arg: arg != '--', args)))

    config_file_paths = cls.get_config_file_paths(env=env, args=args)
    config_files_products = [filecontent_for(p) for p in config_file_paths]
    pre_bootstrap_config = Config.load_file_contents(config_files_products)

    initial_bootstrap_options = cls.parse_bootstrap_options(env, bargs, pre_bootstrap_config)
    bootstrap_option_values = initial_bootstrap_options.for_global_scope()

    # Now re-read the config, post-bootstrapping. Note the order: First whatever we bootstrapped
    # from (typically pants.ini), then config override, then rcfiles.
    full_configpaths = pre_bootstrap_config.sources()
    if bootstrap_option_values.pantsrc:
      rcfiles = [os.path.expanduser(str(rcfile)) for rcfile in bootstrap_option_values.pantsrc_files]
      existing_rcfiles = list(filter(os.path.exists, rcfiles))
      full_configpaths.extend(existing_rcfiles)

    full_config_files_products = [filecontent_for(p) for p in full_configpaths]
    post_bootstrap_config = Config.load_file_contents(
      full_config_files_products,
      seed_values=bootstrap_option_values
    )

    env_tuples = tuple(sorted(iteritems(env), key=lambda x: x[0]))
    return cls(env_tuples=env_tuples, bootstrap_args=bargs, args=args, config=post_bootstrap_config)
455738
def create_venv(local='y', test='y', general='y'):
    """"""
    if not path.isdir(project_paths.venv):
        execute('virtualenv', '--distribute', '--no-site-packages', project_paths.venv)
        project.execute_python('-m', 'easy_install', 'pip')
    if local.lower() == 'y' and project_paths.local_requirements:
        project.execute_pip('install', '--upgrade', '-r', project_paths.local_requirements)
    if test.lower() == 'y' and project_paths.test_requirements:
        project.execute_pip('install', '--upgrade', '-r', project_paths.test_requirements)
    if general.lower() == 'y' and project_paths.requirements_txt:
        project.execute_pip('install', '--upgrade', '-r', project_paths.requirements_txt)
1325330
public boolean shouldConfigureVirtualenv() {
    if(this.configureVirtualenv == ConfigureVirtualenv.NO) {
      return false;
    } else if(this.configureVirtualenv == ConfigureVirtualenv.YES) {
      return true;
    } else {
      final Optional<File> whichVirtualenv = this.which("virtualenv");
      return whichVirtualenv.isPresent();
    }
  }