-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"directory is not empty" when installing a package via pip #4734
Comments
I got rid of this issue by using "Run as Administrator" when running cmd.exe. Seems weird on Windows, but is it a permissions problem? |
So... The only way this can happen is if somehow pip is unable to delete the folder after trying to 5 times over a period of 3 seconds. The only reason I think this can happen would be something like an Antivirus holding a reference/lock to that folder. I'm curious what the output of |
The retry decorator applies to the top-level rmtree operation, not to each individual directory in the tree. For large trees, it's possible that the total number of retries exceeds the limit, even if no directory ever required more than 2 attempts. So perhaps the decorator should be moved to the error handler, and the handler changed so that it always retries, not just when it changed the file mode. |
And to answer your other question: whenever this happens to me, I find that the directory is always empty by the time I can look at it, and can be removed manually without any problem. I agree that it's probably interference from anti-virus software. I'm using Windows 7 with Avast, pip 10.0.1. |
if you are getting issue with nonempty directory problem, just run as administrator privileges and select "just me" in "install for" option. |
We're also having this issue sporadically, likely due to antivirus (Cylance) inspecting the to-be-removed files. It seems like the retry fix from #2397 does not seem to help here. Here's a process monitor capture for the file/folder in question, where it's visible that Cylance starts to read the file slightly after pip attempts to delete. |
This sounds like a bug in the antivirus software. If it can't be configured to read files with a mode that allows deletion, then maybe it can be told not to scan pip's temporary directory? |
I had the same error updating some modules with Edit: The windows is running Sophos AV-something (corporate stuff). |
We're also seeing this when the directory is on NFS: https://forum.spinalcordmri.org/t/installing-sct-4-3-fails-pycache-not-empty/493. Is there some environment var we can set to make pip more tolerant of slow disks? |
Recently:
Sometimes I also see similar error when I delete folder with Far Manager. It tells me "Folder is not empty" and asks what to do with this kind of error, I just select "Skip all", so all files are deleted and all folders where it's possible. In the second step I just delete remaining folders. So maybe this is a solution for recursively deleting folders - first delete what you can, ignoring the "dir not empty" errors, after that if there were such errors, wait 2 seconds and retry the whole procedure. |
And maybe do 5 retries - but with 2 seconds interval between them. Should be enough. |
could be your IDE locking files. in my case it worked after closing vscode |
or antivirus - and this is more frequent |
I don’t think retries help that much, to be honest, because in my experience the common cases are IDE or Explorer, both won’t unlock the file no matter how many times you try. Instead, we can simply show a warning message telling the user something fails to delete, move the thing to somewhere else (the dash-prefixed scheme we use elsewhere is good enough, or the Feel free to submit a pull request for this. |
There's a bug in Windows or maybe caching issues - when you delete all files from folder and them immediately try to delete folder, sometimes it thinks there are still files inside. It have nothing about IDE or explorer, and retries will help. |
Description:
When I install packages using pip, I am usually (but not always) getting exceptions that occur AFTER the message that the package was successfully installed.
Please note that this is an Anaconda distribution, but I was running pip instead of conda nonetheless. This is on a work computer so I suppose it could be antivirus-related, but I don't have anything specific to suggest that.
Potentially related issue here (#2892) except that the directories in my case were not all that deep.
Another potentially related issue here (#306) but I take it from the fact that the issue was closed that I may have encountered something new.
What I've run:
The text was updated successfully, but these errors were encountered: