pip
pip copied to clipboard
Ignore errors in temporary directory cleanup
Pip frequently fails on windows with a PermissionError in temporary directory cleanup after it has already successfully installed upgraded/uninstalled a package.
E.g if you have import matplotlib
in one python session and run
> pip install matplotlib==3.4.3
in another, you get
...
Installing collected packages: matplotlib
Attempting uninstall: matplotlib
Found existing installation: matplotlib 3.4.3
Uninstalling matplotlib-3.4.3:
Successfully uninstalled matplotlib-3.4.3
ERROR: Could not install packages due to an OSError: [WinError 5] Access is denied: 'C:\\Users\\ales\\.envs\\Lib\\site-packages\\~4tplotlib\\ft2font.cp39-win_amd64.pyd'
Check the permissions.
(note the '\\~4tplotlib\\' name) indicating this is failure to remove an temp backup; a new package is already fully installed at this point)
With this applied
Installing collected packages: matplotlib
Attempting uninstall: matplotlib
Found existing installation: matplotlib 3.4.2
Uninstalling matplotlib-3.4.2:
Successfully uninstalled matplotlib-3.4.2
WARNING: Failed to remove a temporary file 'C:\Users\ales\.envs\Lib\site-packages\~-tplotlib\ft2font.cp39-win_amd64.pyd' due to PermissionError: [WinError 5] Access is denied: 'C:\\Users\\ales\\.envs\\Lib\\site-packages\\~-tplotlib\\ft2font.cp39-win_amd64.pyd'.
You can safely remove it manually.
WARNING: Failed to remove a temporary file 'C:\Users\ales\.envs\Lib\site-packages\~-tplotlib\_c_internal_utils.cp39-win_amd64.pyd' due to PermissionError: [WinError 5] Access is denied: 'C:\\Users\\ales\\.envs\\Lib\\site-packages\\~-tplotlib\\_c_internal_utils.cp39-win_amd64.pyd'.
You can safely remove it manually.
WARNING: Failed to remove a temporary file 'C:\Users\ales\.envs\Lib\site-packages\~-tplotlib\_path.cp39-win_amd64.pyd' due to PermissionError: [WinError 5] Access is denied: 'C:\\Users\\ales\\.envs\\Lib\\site-packages\\~-tplotlib\\_path.cp39-win_amd64.pyd'.
You can safely remove it manually.
WARNING: Failed to remove a temporary file 'C:\Users\ales\.envs\Lib\site-packages\~-tplotlib' due to OSError: [WinError 145] The directory is not empty: 'C:\\Users\\ales\\.envs\\Lib\\site-packages\\~-tplotlib'.
You can safely remove it manually.
Successfully installed matplotlib-3.4.3
This also fixes https://github.com/pypa/pip/issues/6327 (similar problem on nfs)
I wonder how viable it’d be to aggregate these removal failures and show just one warning message before the process exits instead. This can be quite spammy if a package contains a lot of files cannot be removed.
Is this even viable ? As @uranusjr said, it would be a mess when installing packages containing many files, and would spam the console. Perhaps leave this as an option ?
I have changed it so only a single warning is displayed for a temporary directory.
...
Installing collected packages: matplotlib
Attempting uninstall: matplotlib
Found existing installation: matplotlib 3.4.3
Uninstalling matplotlib-3.4.3:
Successfully uninstalled matplotlib-3.4.3
WARNING: Failed to remove contents of a temporary directory 'C:\Users\ales\.envs\Lib\site-packages\~6tplotlib'.
You can safely remove it manually.
Successfully installed matplotlib-3.4.2
This is still done when TempDirectory.cleanup
is called.
TempDirectory
does have means of being globally_managed
(to cleanup at exit?), but the 'uninstall backups' do not use this and I do not feel comfortable changing this.
Hi. Is there anything blocking this PR being merged? This will fix a problem we are hitting regularly. Many thanks