def real_python3(python, version_dict):
args = [python, '<STR_LIT:-c>', '<STR_LIT>']<EOL>try:<EOL><INDENT>output = subprocess.check_output(args, stderr=subprocess.STDOUT)<EOL>prefix = output.decode('<STR_LIT>').strip()<EOL><DEDENT>except subprocess.CalledProcessError:<EOL><INDENT>return python<EOL><DEDENT>if os.name == '<STR_LIT>':  <EOL><INDENT>paths = [os.path.join(prefix, os.path.basename(python))]<EOL><DEDENT>else:<EOL><INDENT>paths = [os.path.join(prefix, '<STR_LIT>', python) for python in [<EOL>os.path.basename(python),<EOL>'<STR_LIT>' % version_dict,<EOL>'<STR_LIT>' % version_dict,<EOL>'<STR_LIT>' % version_dict,<EOL>'<STR_LIT>',<EOL>]]<EOL><DEDENT>for path in paths:<EOL><INDENT>if os.path.isfile(path):<EOL><INDENT>break<EOL><DEDENT><DEDENT>else:<EOL><INDENT>path = None<EOL><DEDENT>assert path, '<STR_LIT>'.join(['<STR_LIT>'] + paths)<EOL>v1 = subprocess.check_output([python, '<STR_LIT>'])<EOL>v2 = subprocess.check_output([path, '<STR_LIT>'])<EOL>assert v1 == v2, '<STR_LIT>' % (v1, v2)<EOL>return path<EOL>
Determine the path of the real python executable, which is then used for
venv creation. This is necessary, because an active virtualenv environment
will cause venv creation to malfunction. By getting the path of the real
executable, this issue is bypassed.

The provided `python` path may be either:
- A real python executable
- A virtual python executable (with venv)
- A virtual python executable (with virtualenv)

If the virtual environment was created with virtualenv, the `sys` module
will have a `real_prefix` attribute, which points to the directory where
the real python files are installed.

If `real_prefix` is not present, the environment was not created with
virtualenv, and the python executable is safe to use.

The `version_dict` is used for attempting to derive the real executable
path. This is necessary when the name of the virtual python executable
does not exist in the Python installation's directory. For example, if
the `basepython` is explicitly set to `python`, tox will use this name
instead of attempting `pythonX.Y`. In many cases, Python 3 installations
do not contain an executable named `python`, so we attempt to derive this
from the version info. e.g., `python3.6.5`, `python3.6`, then `python3`.