Repository: python-poetry/poetry

Issue:
Poetry fails with KeyError if the PATH environment variable is not present
- [x] I am on the [latest](https://github.com/python-poetry/poetry/releases/latest) Poetry version.
- [x] I have searched the [issues](https://github.com/python-poetry/poetry/issues) of this repo and believe that this is not a duplicate.
- [x] If an exception occurs when executing a command, I executed it again in debug mode (`-vvv` option).

- **OS version and name**: Ubuntu 18.04
- **Poetry version**: 1.0.10

## Issue

When running in CI using a docker container the `PATH` environment variable is not set and causes an issue with poetry. Unfortunately I don't see any traceback. Here's a snipped showing the issue:

```
root@5d1e49d5433c:~/src# unset PATH
root@5d1e49d5433c:~/src# /usr/local/bin/poetry run -vvv pip install pip

[KeyError]
'PATH'
```



Discussion:
With the debugger I was able to get the traceback:

```
(Pdb) traceback.print_tb(e.__traceback__)
  File "/usr/local/lib/python3.6/dist-packages/clikit/console_application.py", line 131, in run
    status_code = command.handle(parsed_args, io)
  File "/usr/local/lib/python3.6/dist-packages/clikit/api/command/command.py", line 120, in handle
    status_code = self._do_handle(args, io)
  File "/usr/local/lib/python3.6/dist-packages/clikit/api/command/command.py", line 163, in _do_handle
    self._dispatcher.dispatch(PRE_HANDLE, event)
  File "/usr/local/lib/python3.6/dist-packages/clikit/api/event/event_dispatcher.py", line 22, in dispatch
    self._do_dispatch(listeners, event_name, event)
  File "/usr/local/lib/python3.6/dist-packages/clikit/api/event/event_dispatcher.py", line 89, in _do_dispatch
    listener(event, event_name, self)
  File "/usr/local/lib/python3.6/dist-packages/poetry/console/config/application_config.py", line 92, in set_env
    env = env_manager.create_venv(io)
  File "/usr/local/lib/python3.6/dist-packages/poetry/utils/env.py", line 490, in create_venv
    env = self.get(reload=True)
  File "/usr/local/lib/python3.6/dist-packages/poetry/utils/env.py", line 333, in get
    return VirtualEnv(venv)
  File "/usr/local/lib/python3.6/dist-packages/poetry/utils/env.py", line 1045, in __init__
    self._base = Path(self.run("python", "-", input_=GET_BASE_PREFIX).strip())
  File "/usr/local/lib/python3.6/dist-packages/poetry/utils/env.py", line 879, in run
    return self._run(cmd, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/poetry/utils/env.py", line 1106, in _run
    os.environ["PATH"] = self._updated_path()
  File "/usr/local/lib/python3.6/dist-packages/poetry/utils/env.py", line 1138, in _updated_path
    return os.pathsep.join([str(self._bin_dir), os.environ["PATH"]])
  File "/usr/lib/python3.6/os.py", line 669, in __getitem__
    raise KeyError(key) from None
```

Resolving patch:
diff --git a/poetry/utils/env.py b/poetry/utils/env.py
--- a/poetry/utils/env.py
+++ b/poetry/utils/env.py
@@ -1212,7 +1212,7 @@ def unset_env(self, key):
             del os.environ[key]
 
     def _updated_path(self):
-        return os.pathsep.join([str(self._bin_dir), os.environ["PATH"]])
+        return os.pathsep.join([str(self._bin_dir), os.environ.get("PATH", "")])
 
 
 class NullEnv(SystemEnv):


Test patch: