diff --git a/news/2877.bugfix b/news/2877.bugfix new file mode 100644 index 0000000000..c5b23a31a3 --- /dev/null +++ b/news/2877.bugfix @@ -0,0 +1 @@ +Fixed a bug where `pipenv` crashes when the `WORKON_HOME` directory does not exist. diff --git a/pipenv/utils.py b/pipenv/utils.py index b7295c2921..0e1f851d1d 100644 --- 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):