# Buggy code
def __init__(self):
    # qualifies the python
    self.platform = sys.platform
    self.implementation = platform.python_implementation()
    self.pypy_version_info = (
        tuple(sys.pypy_version_info) if self.implementation == "PyPy" else None
    )

    # this is a tuple in earlier, struct later, unify to our own named tuple
    self.version_info = VersionInfo(*list(sys.version_info))
    self.architecture = 64 if sys.maxsize > 2**32 else 32

    self.executable = sys.executable  # executable we were called with
    self.original_executable = self.executable
    self.base_executable = getattr(
        sys, "_base_executable", None
    )  # some platforms may set this

    self.version = sys.version
    self.os = os.name

    # information about the prefix - determines python home
    self.prefix = getattr(sys, "prefix", None)  # prefix we think
    self.base_prefix = getattr(sys, "base_prefix", None)  # venv
    self.real_prefix = getattr(sys, "real_prefix", None)  # old virtualenv

    # information about the exec prefix - dynamic stdlib modules
    self.base_exec_prefix = getattr(sys, "base_exec_prefix", None)
    self.exec_prefix = getattr(sys, "exec_prefix", None)

    try:
        __import__("venv")
        has = True
    except ImportError:
        has = False
    self.has_venv = has
    self.path = sys.path
    self.file_system_encoding = sys.getfilesystemencoding()
    self.stdout_encoding = getattr(sys.stdout, "encoding", None)


# Traceback (ModuleNotFoundError)
$ <scl_base>/bin/virtualenv --python <scl_base>/bin/python --always-copy --verbose TEST
Running virtualenv with interpreter <scl_base>/bin/python
Using base prefix '<scl_base>'
Creating <somedir>/TEST/lib/python3.6
Copying to <somedir>/TEST/lib64
Symlinking Python bootstrap modules
Copying to <somedir>/TEST/lib/python3.6/config-3.6m-x86_64-linux-gnu
Copying to <somedir>/TEST/lib/python3.6/lib-dynload
Copying to <somedir>/TEST/lib64/python3.6/os.py
Ignoring built-in bootstrap module: posix
Copying to <somedir>/TEST/lib64/python3.6/posixpath.py
Cannot import bootstrap module: nt
Copying to <somedir>/TEST/lib64/python3.6/ntpath.py
Copying to <somedir>/TEST/lib64/python3.6/genericpath.py
Copying to <somedir>/TEST/lib64/python3.6/fnmatch.py
Copying to <somedir>/TEST/lib64/python3.6/locale.py
Copying to <somedir>/TEST/lib64/python3.6/encodings
Copying to <somedir>/TEST/lib64/python3.6/codecs.py
Copying to <somedir>/TEST/lib64/python3.6/stat.py
Cannot import bootstrap module: UserDict
Creating parent directories for <somedir>/TEST/lib64/python3.6/lib-dynload
Copying to <somedir>/TEST/lib64/python3.6/lib-dynload/readline.cpython-36m-x86_64-linux-gnu.so
Cannot import bootstrap module: copy_reg
Copying to <somedir>/TEST/lib64/python3.6/types.py
Copying to <somedir>/TEST/lib64/python3.6/re.py
Cannot import bootstrap module: sre
Copying to <somedir>/TEST/lib64/python3.6/sre_parse.py
Copying to <somedir>/TEST/lib64/python3.6/sre_constants.py
Copying to <somedir>/TEST/lib64/python3.6/sre_compile.py
Copying to <somedir>/TEST/lib64/python3.6/lib-dynload/zlib.cpython-36m-x86_64-linux-gnu.so
Cannot import bootstrap module: _abcoll
Copying to <somedir>/TEST/lib64/python3.6/warnings.py
Copying to <somedir>/TEST/lib64/python3.6/linecache.py
Copying to <somedir>/TEST/lib64/python3.6/abc.py
Copying to <somedir>/TEST/lib64/python3.6/io.py
Copying to <somedir>/TEST/lib64/python3.6/_weakrefset.py
Copying to <somedir>/TEST/lib64/python3.6/copyreg.py
Copying to <somedir>/TEST/lib64/python3.6/tempfile.py
Copying to <somedir>/TEST/lib64/python3.6/random.py
Copying to <somedir>/TEST/lib64/python3.6/__future__.py
Copying to <somedir>/TEST/lib64/python3.6/collections
Copying to <somedir>/TEST/lib64/python3.6/keyword.py
Copying to <somedir>/TEST/lib64/python3.6/tarfile.py
Copying to <somedir>/TEST/lib64/python3.6/shutil.py
Copying to <somedir>/TEST/lib64/python3.6/struct.py
Copying to <somedir>/TEST/lib64/python3.6/copy.py
Copying to <somedir>/TEST/lib64/python3.6/tokenize.py
Copying to <somedir>/TEST/lib64/python3.6/token.py
Copying to <somedir>/TEST/lib64/python3.6/functools.py
Copying to <somedir>/TEST/lib64/python3.6/heapq.py
Copying to <somedir>/TEST/lib64/python3.6/bisect.py
Copying to <somedir>/TEST/lib64/python3.6/weakref.py
Copying to <somedir>/TEST/lib64/python3.6/reprlib.py
Copying to <somedir>/TEST/lib64/python3.6/base64.py
Copying to <somedir>/TEST/lib64/python3.6/_dummy_thread.py
Copying to <somedir>/TEST/lib64/python3.6/hashlib.py
Copying to <somedir>/TEST/lib64/python3.6/hmac.py
Copying to <somedir>/TEST/lib64/python3.6/imp.py
Copying to <somedir>/TEST/lib64/python3.6/importlib
Copying to <somedir>/TEST/lib64/python3.6/rlcompleter.py
Copying to <somedir>/TEST/lib64/python3.6/operator.py
Copying to <somedir>/TEST/lib64/python3.6/_collections_abc.py
Copying to <somedir>/TEST/lib64/python3.6/_bootlocale.py
Copying to <somedir>/TEST/lib64/python3.6/enum.py
No LICENSE.txt / LICENSE found in source
Creating <somedir>/TEST/lib/python3.6/site-packages
Writing <somedir>/TEST/lib64/python3.6/site.py
Writing <somedir>/TEST/lib64/python3.6/orig-prefix.txt
Writing <somedir>/TEST/lib64/python3.6/no-global-site-packages.txt
Creating <somedir>/TEST/bin
New python executable in <somedir>/TEST/bin/python
Changed mode of <somedir>/TEST/bin/python to 0o775
Copying to <somedir>/TEST/bin/python3
Copying to <somedir>/TEST/bin/python3.6
Testing executable with <somedir>/TEST/bin/python -c "import sys;out=sys.stdout;getattr(out, "buffer", out).write(sys.prefix.encode("utf-8"))"
Got sys.prefix result: '<somedir>/TEST'
Creating <somedir>/TEST/lib64/python3.6/distutils
Writing <somedir>/TEST/lib64/python3.6/distutils/__init__.py
Writing <somedir>/TEST/lib64/python3.6/distutils/distutils.cfg
Traceback (most recent call last):
File "<scl_base>/lib64/python3.6/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "<scl_base>/lib64/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "<scl_base>/usr/lib/python3.6/site-packages/virtualenv_support/pip-19.0.3-py2.py3-none-any.whl/pip/__main__.py", line 16, in <module>
File "<scl_base>/usr/lib/python3.6/site-packages/virtualenv_support/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/__init__.py", line 19, in <module>
File "<scl_base>/usr/lib/python3.6/site-packages/virtualenv_support/pip-19.0.3-py2.py3-none-any.whl/pip/_vendor/urllib3/__init__.py", line 8, in <module>
File "<scl_base>/usr/lib/python3.6/site-packages/virtualenv_support/pip-19.0.3-py2.py3-none-any.whl/pip/_vendor/urllib3/connectionpool.py", line 7, in <module>
File "<scl_base>/lib64/python3.6/socket.py", line 49, in <module>
import _socket
ModuleNotFoundError: No module named '_socket'
Command <somedir>/TEST/bin/python -m pip config list had error code 1
Installing setuptools, pip, wheel...

Traceback (most recent call last):
File "<stdin>", line 4, in <module>
File "<somedir>/TEST/lib64/python3.6/tempfile.py", line 45, in <module>
from random import Random as _Random
File "<somedir>/TEST/lib64/python3.6/random.py", line 42, in <module>
from math import log as _log, exp as _exp, pi as _pi, e as _e, ceil as _ceil
ModuleNotFoundError: No module named 'math'
Complete output from command <somedir>/TEST/bin/python - setuptools pip wheel:
Traceback (most recent call last):
File "<stdin>", line 4, in <module>
File "<somedir>/TEST/lib64/python3.6/tempfile.py", line 45, in <module>
from random import Random as _Random
File "<somedir>/TEST/lib64/python3.6/random.py", line 42, in <module>
from math import log as _log, exp as _exp, pi as _pi, e as _e, ceil as _ceil
ModuleNotFoundError: No module named 'math'
----------------------------------------
...Installing setuptools, pip, wheel...done.
Traceback (most recent call last):
File "<scl_base>/usr/lib/python3.6/site-packages/virtualenv.py", line 2567, in <module>
main()
File "<scl_base>/usr/lib/python3.6/site-packages/virtualenv.py", line 793, in main
symlink=options.symlink,
File "<scl_base>/usr/lib/python3.6/site-packages/virtualenv.py", line 1088, in create_environment
install_wheel(to_install, py_executable, search_dirs, download=download)
File "<scl_base>/usr/lib/python3.6/site-packages/virtualenv.py", line 935, in install_wheel
_install_wheel_with_search_dir(download, project_names, py_executable, search_dirs)
File "<scl_base>/usr/lib/python3.6/site-packages/virtualenv.py", line 1025, in _install_wheel_with_search_dir
call_subprocess(cmd, show_stdout=False, extra_env=env, stdin=script)
File "<scl_base>/usr/lib/python3.6/site-packages/virtualenv.py", line 886, in call_subprocess
raise OSError("Command {} failed with error code {}".format(cmd_desc, proc.returncode))
OSError: Command <somedir>/TEST/bin/python - setuptools pip wheel failed with error code 1

# Fixed code
def __init__(self):
    def u(v):
        return v.decode("utf-8") if isinstance(v, bytes) else v

    # qualifies the python
    self.platform = u(sys.platform)
    self.implementation = u(platform.python_implementation())
    if self.implementation == "PyPy":
        self.pypy_version_info = tuple(u(i) for i in sys.pypy_version_info)

    # this is a tuple in earlier, struct later, unify to our own named tuple
    self.version_info = VersionInfo(*list(u(i) for i in sys.version_info))
    self.architecture = 64 if sys.maxsize > 2**32 else 32

    self.executable = u(sys.executable)  # executable we were called with
    self.original_executable = u(self.executable)
    self.base_executable = u(
        getattr(sys, "_base_executable", None)
    )  # some platforms may set this

    self.version = u(sys.version)
    self.os = u(os.name)

    # information about the prefix - determines python home
    self.prefix = u(getattr(sys, "prefix", None))  # prefix we think
    self.base_prefix = u(getattr(sys, "base_prefix", None))  # venv
    self.real_prefix = u(getattr(sys, "real_prefix", None))  # old virtualenv

    # information about the exec prefix - dynamic stdlib modules
    self.base_exec_prefix = u(getattr(sys, "base_exec_prefix", None))
    self.exec_prefix = u(getattr(sys, "exec_prefix", None))

    try:
        __import__("venv")
        has = True
    except ImportError:
        has = False
    self.has_venv = has
    self.path = [u(i) for i in sys.path]
    self.file_system_encoding = u(sys.getfilesystemencoding())
    self.stdout_encoding = u(getattr(sys.stdout, "encoding", None))

    self.sysconfig_paths = {
        u(i): u(sysconfig.get_path(i, expand=False)) for i in sysconfig.get_path_names()
    }
    config_var_keys = set()
    for element in self.sysconfig_paths.values():
        for k in _CONF_VAR_RE.findall(element):
            config_var_keys.add(u(k[1:-1]))
    self.sysconfig_config_vars = {
        u(i): u(sysconfig.get_config_var(i)) for i in config_var_keys
    }

    self.distutils_install = {u(k): u(v) for k, v in self._distutils_install().items()}