# Buggy code
def run_install_command(self, packages, action, options=()):
    argv = self.envconfig.install_command[:]
    i = argv.index("{packages}")
    argv[i : i + 1] = packages
    if "{opts}" in argv:
        i = argv.index("{opts}")
        argv[i : i + 1] = list(options)

    for x in (
        "PIP_RESPECT_VIRTUALENV",
        "PIP_REQUIRE_VIRTUALENV",
        "__PYVENV_LAUNCHER__",
    ):
        os.environ.pop(x, None)

    if "PYTHONPATH" not in self.envconfig.passenv:
        # If PYTHONPATH not explicitly asked for, remove it.
        if "PYTHONPATH" in os.environ:
            self.session.report.warning(
                "Discarding $PYTHONPATH from environment, to override "
                "specify PYTHONPATH in 'passenv' in your configuration."
            )
            os.environ.pop("PYTHONPATH")

    old_stdout = sys.stdout
    sys.stdout = codecs.getwriter("utf8")(sys.stdout)
    try:
        self._pcall(
            argv,
            cwd=self.envconfig.config.toxinidir,
            action=action,
            redirect=self.session.report.verbosity < 2,
        )
    finally:
        sys.stdout = old_stdout


# Traceback (pip._internal.exceptions.InstallationError)
GLOB sdist-make: /tmp/foo/setup.py
py36 inst-nodeps: /tmp/foo/.tox/dist/foo-0.0.0.zip
ERROR: invocation failed (exit code 1), logfile: /tmp/foo/.tox/py36/log/py36-3.log
ERROR: actionid: py36
msg: installpkg
cmdargs: ['/tmp/foo/.tox/py36/bin/pip', 'install', '-U', '--no-deps', '/tmp/foo/.tox/dist/foo-0.0.0.zip']

Can not perform a '--user' install. User site-packages are not visible in this virtualenv.
Exception information:
Traceback (most recent call last):
File "/tmp/foo/.tox/py36/lib/python3.6/site-packages/pip/_internal/basecommand.py", line 228, in main
status = self.run(options, args)
File "/tmp/foo/.tox/py36/lib/python3.6/site-packages/pip/_internal/commands/install.py", line 218, in run
"Can not perform a '--user' install. User site-packages "
pip._internal.exceptions.InstallationError: Can not perform a '--user' install. User site-packages are not visible in this virtualenv.

py36 installed: foo==0.0.0
_____________________________________________________________________________________________ summary ______________________________________________________________________________________________
ERROR:   py36: InvocationError for command /tmp/foo/.tox/py36/bin/pip install -U --no-deps /tmp/foo/.tox/dist/foo-0.0.0.zip (see /tmp/foo/.tox/py36/log/py36-3.log) (exited with code 1)

# Fixed code
def run_install_command(self, packages, action, options=()):
    def expand(val):
        # expand an install command
        if val == "{packages}":
            for package in packages:
                yield package
        elif val == "{opts}":
            for opt in options:
                yield opt
        else:
            yield val

    cmd = list(
        chain.from_iterable(expand(val) for val in self.envconfig.install_command)
    )

    self.ensure_pip_os_environ_ok()

    old_stdout = sys.stdout
    sys.stdout = codecs.getwriter("utf8")(sys.stdout)
    try:
        self._pcall(
            cmd,
            cwd=self.envconfig.config.toxinidir,
            action=action,
            redirect=self.session.report.verbosity < 2,
        )
    finally:
        sys.stdout = old_stdout