Repository: pypa/pipenv

Issue:
Pipenv requires existing folder `~/.local/share/virtualenvs`
##### Issue description

When running the current commit 51cbc2e2f76a7c60f879a608fd96e95faca35f2e of pipenv in a Docker image (like `python:3.6`), one has to manually create the folder `/root/.local/share/virtualenvs` for pipenv to work.

##### Expected result

```
root@851be9e3b8d1:/tmp# pipenv install requests
Creating a virtualenv for this project…
Pipfile: /tmp/Pipfile
Using /usr/local/bin/python (3.6.6) to create virtualenv…
...
```

##### Actual result

```
root@851be9e3b8d1:/tmp# pipenv install requests
Traceback (most recent call last):
  File "/usr/local/bin/pipenv", line 11, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/pipenv/cli.py", line 416, in install
    selective_upgrade=selective_upgrade,
  File "/usr/local/lib/python3.6/site-packages/pipenv/core.py", line 1667, in do_install
    pypi_mirror=pypi_mirror,
  File "/usr/local/lib/python3.6/site-packages/pipenv/core.py", line 553, in ensure_project
    pypi_mirror=pypi_mirror,
  File "/usr/local/lib/python3.6/site-packages/pipenv/core.py", line 471, in ensure_virtualenv
    if not project.virtualenv_exists:
  File "/usr/local/lib/python3.6/site-packages/pipenv/project.py", line 259, in virtualenv_exists
    if self.pipfile_exists and os.path.exists(self.virtualenv_location):
  File "/usr/local/lib/python3.6/site-packages/pipenv/project.py", line 370, in virtualenv_location
    self._virtualenv_location = self.get_location_for_virtualenv()
  File "/usr/local/lib/python3.6/site-packages/pipenv/project.py", line 272, in get_location_for_virtualenv
    name = self.virtualenv_name
  File "/usr/local/lib/python3.6/site-packages/pipenv/project.py", line 356, in virtualenv_name
    sanitized, encoded_hash = self._get_virtualenv_hash(self.name)
  File "/usr/local/lib/python3.6/site-packages/pipenv/project.py", line 340, in _get_virtualenv_hash
    for path in get_workon_home().iterdir():
  File "/usr/local/lib/python3.6/pathlib.py", line 1079, in iterdir
    for name in self._accessor.listdir(self):
  File "/usr/local/lib/python3.6/pathlib.py", line 387, in wrapped
    return strfunc(str(pathobj), *args)
FileNotFoundError: [Errno 2] No such file or directory: '/root/.local/share/virtualenvs'
```

##### Steps to replicate

```bash
docker run -it --rm python:3.6 bash
# inside the container
pip install git+git://github.com/pypa/pipenv.git@51cbc2e2f76a7c60f879a608fd96e95faca35f2e
pipenv install requests
```

To fix:

```bash
# inside the container
mkdir -p /root/.local/share/virtualenvs
```


Discussion:
I’d assume the solution would be to create `~/.local/share/virtualenvs` to make sure it exists.
@uranusjr Can I take this up?
sure, go ahead
@sinscary are you still working on this one or can I take it up?
@Enzime I didn't get time to look at this. You can take it up 👍 

Resolving patch:
diff --git a/pipenv/utils.py b/pipenv/utils.py
--- a/pipenv/utils.py
+++ b/pipenv/utils.py
@@ -1281,7 +1281,10 @@ def get_workon_home():
             workon_home = os.path.join(
                 os.environ.get("XDG_DATA_HOME", "~/.local/share"), "virtualenvs"
             )
-    return Path(os.path.expandvars(workon_home)).expanduser()
+    # Create directory if it does not already exist
+    expanded_path = Path(os.path.expandvars(workon_home)).expanduser()
+    mkdir_p(str(expanded_path))
+    return expanded_path
 
 
 def is_virtual_environment(path):


Test patch: