'Cannot upgrade pip in virtual environment on Windows due to "directory is not empty"
I cannot upgrade pip from 19.0.3 to latest (22.0.3) on Windows with Python 2.7.
I am using a virtual environment (created by python -m venv).
The error is that a directory is not empty when uninstalling. Isn't that expected? Shouldn't it just uninstall anyway?
C:\dev>venv\Scripts\python.exe -m pip install --upgrade pip
Collecting pip
Downloading https://files.pythonhosted.org/packages/6a/df/a6ef77a6574781a668791419ffe366c8acd1c3cf4709d210cb53cd5ce1c2/pip-22.0.3-py3-none-any.whl (2.1MB)
Installing collected packages: pip
Found existing installation: pip 19.0.3
Uninstalling pip-19.0.3:
Could not install packages due to an EnvironmentError: [WinError 145] The directory is not empty: 'c:\dev\venv\lib\site-packages\pip-19.0.3.dist-info\'
I tried re-creating the error on another machine by creating a file at venv\lib\site-packages\pip-19.0.3.dist-info\temp1.txt and then holding an exclusive lock on the file with notepad >venv\lib\site-packages\pip-19.0.3.dist-info\temp1.txt. But pip was able to upgrade just fine; the pip-19.0.3.dist-info directory was not fully deleted, but pip uninstall/install succeeded.
So what is going on? Why would it complain about a directory it doesn't actually need to delete being non-empty?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
