diff --git a/changelog.d/1203.bugfix.md b/changelog.d/1203.bugfix.md new file mode 100644 index 0000000000..67a47c1277 --- /dev/null +++ b/changelog.d/1203.bugfix.md @@ -0,0 +1 @@ +Let self-managed pipx uninstall itself on windows again. diff --git a/src/pipx/util.py b/src/pipx/util.py index 8a498e853a..ad5ab4739f 100644 --- a/src/pipx/util.py +++ b/src/pipx/util.py @@ -53,10 +53,11 @@ def rmdir(path: Path, safe_rm: bool = True) -> None: return logger.info(f"removing directory {path}") - try: - shutil.rmtree(path) - except FileNotFoundError: - pass + # Windows doesn't let us delete or overwrite files that are being run + # But it does let us rename/move it. To get around this issue, we can move + # the file to a temporary folder (to be deleted at a later time) + # So, if safe_rm is True, we ignore any errors and move the file to the trash with below code + shutil.rmtree(path, ignore_errors=safe_rm) # move it to be deleted later if it still exists if path.is_dir():