-
Notifications
You must be signed in to change notification settings - Fork 476
Description
Describe the bug
When pipx manages itself (pipx is installed as a pipx app) on Windows, it is no longer able to uninstall itself (since #1168 was merged).
The following error message is shown:
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "C:\Users\not_of_interest\.local\bin\pipx.exe\__main__.py", line 7, in <module>
File "C:\Users\not_of_interest\.local\pipx\venvs\pipx\Lib\site-packages\pipx\main.py", line 914, in cli
File "C:\Users\not_of_interest\.local\pipx\venvs\pipx\Lib\site-packages\pipx\main.py", line 274, in run_pipx_command
File "C:\Users\not_of_interest\.local\pipx\venvs\pipx\Lib\site-packages\pipx\commands\reinstall.py", line 53, in reinstall
File "C:\Users\not_of_interest\.local\pipx\venvs\pipx\Lib\site-packages\pipx\commands\uninstall.py", line 151, in uninstall
File "C:\Users\not_of_interest\.local\pipx\venvs\pipx\Lib\site-packages\pipx\util.py", line 57, in rmdir
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.496.0_x64__qbz5n2kfra8p0\Lib\shutil.py", line 808, in rmtree
return _rmtree_unsafe(path, onexc)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.496.0_x64__qbz5n2kfra8p0\Lib\shutil.py", line 631, in _rmtree_unsafe
_rmtree_unsafe(fullname, onexc)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.496.0_x64__qbz5n2kfra8p0\Lib\shutil.py", line 636, in _rmtree_unsafe
onexc(os.unlink, fullname, err)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.496.0_x64__qbz5n2kfra8p0\Lib\shutil.py", line 634, in _rmtree_unsafe
os.unlink(fullname)
PermissionError: [WinError 5] Access denied: 'C:\\Users\\not_of_interest\\.local\\pipx\\venvs\\pipx\\Scripts\\python.exe'
The venv folder is not deleted, as the Scripts\python.exe
is still inside. This also causes following installs to break (one has to delete the remaining folder manually).
How to reproduce
On Windows:
- Install pipx in pipx
pipx uninstall pipx
Expected behavior
The locked (as in use) python.exe
should be moved to the trash, as introduced in line 64-76 of 6e1907b#diff-c69ab827b9b12c8c732a2cfaf1056304894e775d94224f94e56313bf1f7d299f.
Analysis
In #1168, the os.system(f'rmdir /S /Q "{str(path)}"')
to delete the folder was replaced by shutil.rmtree(path)
. The first one printed an error to the stdout it still fell through to the code introduced by #718 linked in the "Expected behavior" section, which then moved the undeletable executable and thus resolved the issue. The latter one (now) just fails with the stated error.
If any of the maintainers give feedback, how to solve it (restore the os.system
-call?), I'm happy to provide a PR (shouldn't be too hard 😆).
Personal note
Tbh #1168 is a huge disaster imho. Both (little) changes introduced had bad impact on me. One is discribed here, for the other change see my comment #1186 (review). I do not want to blame anyone and hugely appreciate the time of everyone involved here, but this PR really did cost me some sanity now. And as the issue #1195 arising from it shows, I'm not the only one.
Thank you all for a great tool, which I really don't want to miss.