Repository: pypa/pipenv

Issue:
2018.11.14 regression: pipenv install --system --keep-outdated --ignore-pipfile
### Issue description

I have a dockerfile with this line:
`RUN test -f "./Pipfile.lock" && pipenv install --system --keep-outdated --ignore-pipfile || pipenv install --system --skip-lock`
where `Pipfile.lock` does exist, and is sane

### Expected result

The dependencies to be installed.

### Actual result
```
Step 16/26 : RUN test -f "./Pipfile.lock" && pipenv install --system --keep-outdated --ignore-pipfile || pipenv install --system --skip-lock
 ---> Running in d81fb93ac9d5
Installing dependencies from Pipfile.lock (3123d8)…
An error occurred while installing atomicwrites==1.2.1 --hash=sha256:0312ad34fcad8fac3704d441f7b317e50af620823353ec657a53e981f92920c0 --hash=sha256:ec9ae8adaae229e4f8446952d204a3e4b5fdd2d099f9be3aaf556120135fb3ee! Will try again.
An error occurred while installing attrs==18.2.0 --hash=sha256:10cbf6e27dbce8c30807caf056c8eb50917e0eaafe86347671b57254006c3e69 --hash=sha256:ca4be454458f9dec299268d472aaa5a11f67a4ff70093396e1ceae9c76cf4bbb! Will try again.
...
[pipenv.exceptions.InstallError]:   File "/home/user/.local/lib/python3.7/site-packages/pipenv/cli/command.py", line 249, in install
[pipenv.exceptions.InstallError]:       editable_packages=state.installstate.editables,
[pipenv.exceptions.InstallError]:   File "/home/user/.local/lib/python3.7/site-packages/pipenv/core.py", line 1872, in do_install
[pipenv.exceptions.InstallError]:       keep_outdated=keep_outdated
[pipenv.exceptions.InstallError]:   File "/home/user/.local/lib/python3.7/site-packages/pipenv/core.py", line 1232, in do_init
[pipenv.exceptions.InstallError]:       pypi_mirror=pypi_mirror,
[pipenv.exceptions.InstallError]:   File "/home/user/.local/lib/python3.7/site-packages/pipenv/core.py", line 844, in do_install_dependencies
[pipenv.exceptions.InstallError]:       _cleanup_procs(procs, False, failed_deps_queue, retry=False)
[pipenv.exceptions.InstallError]:   File "/home/user/.local/lib/python3.7/site-packages/pipenv/core.py", line 676, in _cleanup_procs
[pipenv.exceptions.InstallError]:       raise exceptions.InstallError(c.dep.name, extra=err_lines)
[pipenv.exceptions.InstallError]: ['Looking in indexes: https://packagecloud.io/syapse/General/pypi/simple, https://pypi.org/simple', 'Collecting atomicwrites==1.2.1 (from -r /tmp/pipenv-v4zkxmcp-requirements/pipenv-yejowapf-requirement.txt (line 1))', '  Downloading https://files.pythonhosted.org/packages/3a/9a/9d878f8d885706e2530402de6417141129a943802c084238914fa6798d97/atomicwrites-1.2.1-py2.py3-none-any.whl', 'Installing collected packages: atomicwrites']
[pipenv.exceptions.InstallError]: ["Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/usr/local/lib/python3.7/site-packages/atomicwrites-1.2.1.dist-info'", 'Consider using the `--user` option or check the permissions.']
ERROR: ERROR: Package installation failed...
```



### Steps to replicate

I haven't yet got a minimal repro, but thought I should flag there is an issue.

A workaround is to modify the line in the Dockerfile where Pipenv is installed, to have an explicit version number:
`RUN python -m pip install --upgrade --user pipenv==v2018.10.9`



Discussion:
Yikes. We need a test for this. Sorry!
Oh, I get it. The issue is that we explicitly disable `--user` during installation, and turn off the user flag.  As of some super recent release, I believe the relevant container distro actually tries to turn this flag _on_. So the conflict is happening with the use of the `--system` flag here because we aren't playing nice in the sandbox.  Let me see.

Resolving patch:
diff --git a/pipenv/core.py b/pipenv/core.py
--- a/pipenv/core.py
+++ b/pipenv/core.py
@@ -725,7 +725,8 @@ def batch_install(deps_list, procs, failed_deps_queue,
                 extra_indexes = indexes[1:]
 
         with vistir.contextmanagers.temp_environ():
-            os.environ["PIP_USER"] = vistir.compat.fs_str("0")
+            if not allow_global:
+                os.environ["PIP_USER"] = vistir.compat.fs_str("0")
             c = pip_install(
                 dep,
                 ignore_hashes=any([ignore_hashes, dep.editable, dep.is_vcs]),
@@ -1899,7 +1900,8 @@ def do_install(
             )
             # pip install:
             with vistir.contextmanagers.temp_environ(), create_spinner("Installing...") as sp:
-                os.environ["PIP_USER"] = vistir.compat.fs_str("0")
+                if not system:
+                    os.environ["PIP_USER"] = vistir.compat.fs_str("0")
                 try:
                     pkg_requirement = Requirement.from_line(pkg_line)
                 except ValueError as e:


Test patch: