pip-system-certs prevents clean uninstall of 'wrapt' package
pip
Reproduction Steps with Using a windows machine with a clean python environment (tested on both 3.7.9 and 3.11.0)
- Install pip-system-certs
- Install wrapt
- Uninstall wrapt
- Observe error
I haven't observed this error with any package other than 'wrapt'.
Console logs:
C:\Code\Troubleshooting\AccessIsDenied
(venv2) λ pip freeze
C:\Code\Troubleshooting\AccessIsDenied
(venv2) λ pip install wrapt
Looking in indexes: https://artifactory.devops.corp.novatel.ca/artifactory/api/pypi/novpypi_virtual_dev/simple
Collecting wrapt
Using cached https://artifactory.devops.corp.novatel.ca/artifactory/api/pypi/novpypi_virtual_dev/packages/packages/b1/8b/f4c02cf1f841dede987f93c37d42256dc4a82cd07173ad8a5458eee1c412/wrapt-1.15.0-cp37-cp37m-win_amd64.whl (35 kB)
Installing collected packages: wrapt
Successfully installed wrapt-1.15.0
C:\Code\Troubleshooting\AccessIsDenied
(venv2) λ pip uninstall wrapt -y
Found existing installation: wrapt 1.15.0
Uninstalling wrapt-1.15.0:
Successfully uninstalled wrapt-1.15.0
C:\Code\Troubleshooting\AccessIsDenied
(venv2) λ pip install wrapt pip-system-certs
Looking in indexes: https://artifactory.devops.corp.novatel.ca/artifactory/api/pypi/novpypi_virtual_dev/simple
Collecting wrapt
Using cached https://artifactory.devops.corp.novatel.ca/artifactory/api/pypi/novpypi_virtual_dev/packages/packages/b1/8b/f4c02cf1f841dede987f93c37d42256dc4a82cd07173ad8a5458eee1c412/wrapt-1.15.0-cp37-cp37m-win_amd64.whl (35 kB)
Collecting pip-system-certs
Using cached https://artifactory.devops.corp.novatel.ca/artifactory/api/pypi/novpypi_virtual_dev/packages/packages/70/82/78c30a18858d484acd13a3aea22ead89c66f200e118d1aa4b4bae392efee/pip_system_certs-4.0-py2.py3-none-any.whl (6.1 kB)
Installing collected packages: wrapt, pip-system-certs
Successfully installed pip-system-certs-4.0 wrapt-1.15.0
C:\Code\Troubleshooting\AccessIsDenied
(venv2) λ pip uninstall wrapt
Found existing installation: wrapt 1.15.0
Uninstalling wrapt-1.15.0:
Would remove:
c:\code\troubleshooting\accessisdenied\venv2\lib\site-packages\wrapt-1.15.0.dist-info\*
c:\code\troubleshooting\accessisdenied\venv2\lib\site-packages\wrapt\*
Proceed (Y/n)? y
Successfully uninstalled wrapt-1.15.0
ERROR: Exception:
Traceback (most recent call last):
File "C:\Code\Troubleshooting\AccessIsDenied\venv2\lib\site-packages\pip\_internal\cli\base_command.py", line 160, in exc_logging_wrapper
status = run_func(*args)
File "C:\Code\Troubleshooting\AccessIsDenied\venv2\lib\site-packages\pip\_internal\commands\uninstall.py", line 110, in run
uninstall_pathset.commit()
File "C:\Code\Troubleshooting\AccessIsDenied\venv2\lib\site-packages\pip\_internal\req\req_uninstall.py", line 424, in commit
self._moved_paths.commit()
File "C:\Code\Troubleshooting\AccessIsDenied\venv2\lib\site-packages\pip\_internal\req\req_uninstall.py", line 277, in commit
save_dir.cleanup()
File "C:\Code\Troubleshooting\AccessIsDenied\venv2\lib\site-packages\pip\_internal\utils\temp_dir.py", line 173, in cleanup
rmtree(self._path)
File "C:\Code\Troubleshooting\AccessIsDenied\venv2\lib\site-packages\pip\_vendor\tenacity\__init__.py", line 328, in wrapped_f
return self(f, *args, **kw)
File "C:\Code\Troubleshooting\AccessIsDenied\venv2\lib\site-packages\pip\_vendor\tenacity\__init__.py", line 408, in __call__
do = self.iter(retry_state=retry_state)
File "C:\Code\Troubleshooting\AccessIsDenied\venv2\lib\site-packages\pip\_vendor\tenacity\__init__.py", line 364, in iter
raise retry_exc.reraise()
File "C:\Code\Troubleshooting\AccessIsDenied\venv2\lib\site-packages\pip\_vendor\tenacity\__init__.py", line 197, in reraise
raise self.last_attempt.result()
File "C:\Tools\Python\Python37\lib\concurrent\futures\_base.py", line 428, in result
return self.__get_result()
File "C:\Tools\Python\Python37\lib\concurrent\futures\_base.py", line 384, in __get_result
raise self._exception
File "C:\Code\Troubleshooting\AccessIsDenied\venv2\lib\site-packages\pip\_vendor\tenacity\__init__.py", line 411, in __call__
result = fn(*args, **kwargs)
File "C:\Code\Troubleshooting\AccessIsDenied\venv2\lib\site-packages\pip\_internal\utils\misc.py", line 129, in rmtree
shutil.rmtree(dir, ignore_errors=ignore_errors, onerror=rmtree_errorhandler)
File "C:\Tools\Python\Python37\lib\shutil.py", line 516, in rmtree
return _rmtree_unsafe(path, onerror)
File "C:\Tools\Python\Python37\lib\shutil.py", line 400, in _rmtree_unsafe
onerror(os.unlink, fullname, sys.exc_info())
File "C:\Tools\Python\Python37\lib\shutil.py", line 398, in _rmtree_unsafe
os.unlink(fullname)
PermissionError: [WinError 5] Access is denied: 'c:\\code\\troubleshooting\\accessisdenied\\venv2\\lib\\site-packages\\~8apt\\_wrappers.cp37-win_amd64.pyd'
It appears that pip-system-certs is somehow locking the '_wrappers.cp37-win_amd64.pyd' during uninstall. The uninstall partially finishes in that the wrapt package is renamed in site-packages, but the one file remains.
After the failed uninstall, pip-system-certs will regularly throw an error around wrapt, despite pip showing that the package is uninstalled:
pip_system_certs: ERROR: could not register module: No module named 'wrapt'
pip-system-certs==4.0
This error was what led me to discover pip-system-certs as the cause in the first place.
Edited by RRHex