return the python executable in the virtualenv.
        Try first sys.executable but use fallbacks.
550598
def _get_python_cmd(self):
        
        file_names = ["pypy.exe", "python.exe", "python"]
        executable = sys.executable
        if executable is not None:
            executable = os.path.split(executable)[1]
            file_names.insert(0, executable)

        return self._get_bin_file(*file_names)
719818
def get_default_shell(environ=None, fallback=_UNSPECIFIED):
    """"""
    if environ is None:
        environ = os.environ
    # If the option is specified in the environment, respect it.
    if "PIAS_OPT_SHELL" in environ:
        return environ["PIAS_OPT_SHELL"]
    # Find all candiate shell programs.
    shells = []
    for filename in (environ.get("SHELL"), "bash", "sh"):
        if filename is not None:
            filepath = find_executable(filename, environ)
            if filepath is not None:
                shells.append(filepath)
    # If one of them is an ancestor process, use that.
    for ancestor in get_ancestor_processes():
        if ancestor in shells:
            return ancestor
    # Otherwise use the first option that we found.
    for shell in shells:
        return shell
    # Use an explicit fallback option if given.
    if fallback is not _UNSPECIFIED:
        return fallback
    raise ValueError("Could not find a shell")
287181
def ensure_virtualenv(args, return_values):
    """"""
    def adjust_options(options, args):
        # TODO-TEST: proper error message with no arguments
        venv_path = return_values.venv_path = args[0]

        if venv_path == DEFAULT_VIRTUALENV_PATH or options.prompt == '<dirname>':
            from os.path import abspath, basename, dirname
            options.prompt = '(%s)' % basename(dirname(abspath(venv_path)))
        # end of option munging.

        # there are two python interpreters involved here:
        # 1) the interpreter we're instructing virtualenv to copy
        if options.python is None:
            source_python = None
        else:
            source_python = virtualenv.resolve_interpreter(options.python)
        # 2) the interpreter virtualenv will create
        destination_python = venv_python(venv_path)

        if exists(destination_python):
            reason = invalid_virtualenv_reason(venv_path, source_python, destination_python, options)
            if reason:
                info('Removing invalidated virtualenv. (%s)' % reason)
                run(('rm', '-rf', venv_path))
            else:
                info('Keeping valid virtualenv from previous run.')
                raise SystemExit(0)  # looks good! we're done here.

    # this is actually a documented extension point:
    #   http://virtualenv.readthedocs.org/en/latest/reference.html#adjust_options
    import virtualenv
    virtualenv.adjust_options = adjust_options

    from sys import argv
    argv[:] = ('virtualenv',) + args
    info(colorize(argv))
    raise_on_failure(virtualenv.main)
    # There might not be a venv_path if doing something like "venv= --version"
    # and not actually asking virtualenv to make a venv.
    if return_values.venv_path is not None:
        run(('rm', '-rf', join(return_values.venv_path, 'local')))
574635
def run(self, args=(), env={}):
        

        # the following will call self._get_exec_binary
        return self._exec(self.binary, args=args, env=env)
1041589
def find_executable(name):
    
    for pt in os.environ.get('PATH', '').split(':'):
        candidate = os.path.join(pt, name)
        if os.path.exists(candidate):
            return candidate
888957
def venv_bin(name=None):  # pylint: disable=inconsistent-return-statements
    
    if not hasattr(sys, "real_prefix"):
        easy.error("ERROR: '%s' is not a virtualenv" % (sys.executable,))
        sys.exit(1)

    for bindir in ("bin", "Scripts"):
        bindir = os.path.join(sys.prefix, bindir)
        if os.path.exists(bindir):
            if name:
                bin_ext = os.path.splitext(sys.executable)[1] if sys.platform == 'win32' else ''
                return os.path.join(bindir, name + bin_ext)
            else:
                return bindir

    easy.error("ERROR: Scripts directory not found in '%s'" % (sys.prefix,))
    sys.exit(1)
56129
def pip_create_virtualenv(path=None):
    """"""
    if six.PY2:
        apt_install('python-virtualenv')
    else:
        apt_install('python3-virtualenv')

    if path:
        venv_path = path
    else:
        venv_path = os.path.join(charm_dir(), 'venv')

    if not os.path.exists(venv_path):
        subprocess.check_call(['virtualenv', venv_path])
635139
def executable(self):
        
        exe = util.find_executable('bin/symbiotic', exitOnError=False)
        if exe:
            return exe
        else:
            # this may be the old version of Symbiotic
            return OldSymbiotic.executable(self)
1241793
def _build_env(venv_dir):
    
    # NB: We had to create the because the venv modules wasn't doing what we
    # needed. In particular, if we used it create a venv from an existing venv,
    # it *always* created symlinks back to the original venv's python
    # executables. Then, when you used those linked executables, you ended up
    # interacting with the original venv. I could find no way around this, hence
    # this function.
    prefix = getattr(sys, 'real_prefix', sys.prefix)
    python = Path(prefix) / 'bin' / 'python'
    command = '{} -m venv {}'.format(python, venv_dir)
    try:
        log.info('Creating virtual environment: %s', command)
        subprocess.run(command.split(),
                       stdout=subprocess.PIPE,
                       stderr=subprocess.STDOUT,
                       check=True)
    except subprocess.CalledProcessError as exc:
        log.error("Error creating virtual environment: %s", exc.output)
        raise
826660
def virtualenv(self, virtualenv):
        '''
        
        '''
        # If a boolean is passed then set the internal _skip_virtualenv flag
        if isinstance(virtualenv, bool):
            self._skip_virtualenv = virtualenv
        else:
            self._virtualenv = virtualenv
            if not os.path.isdir(self._virtualenv):
                raise Exception("virtualenv %s not found" % self._virtualenv)
            LOG.info("Using existing virtualenv at %s" % self._virtualenv)
            # use supplied virtualenv path
            self._pkg_venv = self._virtualenv
            self._skip_virtualenv = True
1106973
def python_executable(self):
        """"""
        return self.get(property_name='python_executable',
                        default=sys.executable or os.path.join(self.install_prefix, 'bin', 'python'))
1170335
def get(path, name):  # type: (str, str) -> _EntryPointType
    
    if 'setup.py' in os.listdir(path):
        return _EntryPointType.PYTHON_PACKAGE
    elif name.endswith('.py'):
        return _EntryPointType.PYTHON_PROGRAM
    else:
        return _EntryPointType.COMMAND
332248
def _get_pip_bin(bin_env):
    '''
    
    '''
    if not bin_env:
        logger.debug('pip: Using pip from currently-running Python')
        return [os.path.normpath(sys.executable), '-m', 'pip']

    python_bin = 'python.exe' if salt.utils.platform.is_windows() else 'python'

    def _search_paths(*basedirs):
        ret = []
        for path in basedirs:
            ret.extend([
                os.path.join(path, python_bin),
                os.path.join(path, 'bin', python_bin),
                os.path.join(path, 'Scripts', python_bin)
            ])
        return ret

    # try to get python bin from virtualenv (i.e. bin_env)
    if os.path.isdir(bin_env):
        for bin_path in _search_paths(bin_env):
            if os.path.isfile(bin_path):
                if os.access(bin_path, os.X_OK):
                    logger.debug('pip: Found python binary: %s', bin_path)
                    return [os.path.normpath(bin_path), '-m', 'pip']
                else:
                    logger.debug(
                        'pip: Found python binary by name but it is not '
                        'executable: %s', bin_path
                    )
        raise CommandNotFoundError(
            'Could not find a pip binary in virtualenv {0}'.format(bin_env)
        )

    # bin_env is the python or pip binary
    elif os.access(bin_env, os.X_OK):
        if os.path.isfile(bin_env):
            # If the python binary was passed, return it
            if 'python' in os.path.basename(bin_env):
                return [os.path.normpath(bin_env), '-m', 'pip']
            # We have been passed a pip binary, use the pip binary.
            return [os.path.normpath(bin_env)]

        raise CommandExecutionError(
            'Could not find a pip binary within {0}'.format(bin_env)
        )
    else:
        raise CommandNotFoundError(
            'Access denied to {0}, could not find a pip binary'.format(bin_env)
        )
209604
def _get_exe(prog):
        ''''''
        if prog in prog_to_env_var:
            env_var = prog_to_env_var[prog]
            if env_var in os.environ:
                return os.environ[env_var]

        return prog_to_default[prog]
559978
def restore_cmd(argv):
    """"""

    if len(argv) < 1:
        sys.exit('You must provide a valid virtualenv to target')

    env = argv[0]
    path = workon_home / env
    py = path / env_bin_dir / ('python.exe' if windows else 'python')
    exact_py = py.resolve().name

    return check_call([sys.executable, "-m", "virtualenv", str(path.absolute()), "--python=%s" % exact_py])
302205
def run_from_argv(self, argv):
        
        try:
            return self.main(args=argv[2:], standalone_mode=False)
        except click.ClickException as e:
            if getattr(e.ctx, 'traceback', False):
                raise
            e.show()
            sys.exit(e.exit_code)
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