From 5a16aac6a883525a2ca6f0fb26d02f855a96ba4f Mon Sep 17 00:00:00 2001 From: Etienne Dechamps Date: Sun, 24 Dec 2023 13:07:23 +0000 Subject: [PATCH] Call rmdir with the real path This gets rid of the following warning when using the Microsoft Store version of Python: The system cannot find the path specified. Failed to delete C:\Users\etien\AppData\Local\pipx\pipx\trash. You may need to delete it manually. See also #1164 --- CHANGELOG.md | 1 + src/pipx/util.py | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a45ec8c4c4..7f5443637a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ## dev +- Fix "Failed to delete" error when using Microsoft Store Python - Fix "No pyvenv.cfg file" error when using Microsoft Store Python (#1164) - Add `--quiet` and `--verbose` options for the `pipx` subcommands - [docs] Add Scoop installation instructions diff --git a/src/pipx/util.py b/src/pipx/util.py index 2a9965ef4b..4bba09d6f5 100644 --- a/src/pipx/util.py +++ b/src/pipx/util.py @@ -55,7 +55,9 @@ def rmdir(path: Path, safe_rm: bool = True) -> None: logger.info(f"removing directory {path}") try: if WINDOWS: - os.system(f'rmdir /S /Q "{str(path)}"') + # The packaged app (Microsoft Store) version of Python uses path redirections, but `rmdir` won't follow + # these, so use realpath() to manually apply the redirection first. + os.system(f'rmdir /S /Q "{os.path.realpath(path)}"') else: shutil.rmtree(path) except FileNotFoundError: