diff --git a/CHANGELOG.md b/CHANGELOG.md index da15e33efd..bf10d5052c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ - Pass `--no-input` to pip when output is not piped to parent stdout - Fix program name in generated manual page - Print all environment variables in `pipx environment` +- Return an error message when directory can't be added to PATH successfully ## 1.2.0 diff --git a/src/pipx/commands/ensure_path.py b/src/pipx/commands/ensure_path.py index 8151177b51..6e3de6ffe0 100644 --- a/src/pipx/commands/ensure_path.py +++ b/src/pipx/commands/ensure_path.py @@ -61,14 +61,22 @@ def ensure_path(location: Path, *, force: bool) -> Tuple[bool, bool]: in_current_path = userpath.in_current_path(location_str) if force or (not in_current_path and not need_shell_restart): - userpath.append(location_str, "pipx") - print( - pipx_wrap( - f"Success! Added {location_str} to the PATH environment variable.", - subsequent_indent=" " * 4, + path_added = userpath.append(location_str, "pipx") + if not path_added: + print( + pipx_wrap( + f"{hazard} {location_str} is not added to the PATH environment variable successfully. " + f"You may need to add it to PATH manually.", + subsequent_indent=" " * 4, + ) + ) + else: + print( + pipx_wrap( + f"Success! Added {location_str} to the PATH environment variable.", + subsequent_indent=" " * 4, + ) ) - ) - path_added = True need_shell_restart = userpath.need_shell_restart(location_str) elif not in_current_path and need_shell_restart: print(