-
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
Pip install Error on windows("The directory is not empty") #306
Comments
Hard to say unless you can track it down to reliable steps to reproduce. |
This is could be an issue that a file in the directory is locked, I've seen it happen with CI servers before and folks resort to using unlocker, etc. You can use handle.exe from sysinternals to check which process currently have open handles for the file http://technet.microsoft.com/en-us/sysinternals/bb896655 If you can give more details on what is keeping the file open we might be able to help. We probably should clean up the exception handling and ensure we report an error not a traceback to the user. |
Had this happen to me, and it was due to having a the build directory open in a window. Closing it resolved the issue. |
Happens to me all the time when I run buildout in the Dropbox folder. |
This might be similar an issue I was having with installing pip. I had to: diff -ru pip-1.2.1.orig/pip-1.2.1/setup.py pip-1.2.1/pip-1.2.1/setup.py
--- pip-1.2.1.orig/pip-1.2.1/setup.py 2012-09-01 15:28:40.000000000 -0500
+++ pip-1.2.1/pip-1.2.1/setup.py 2013-01-10 22:35:44.000000000 -0600
@@ -4,10 +4,10 @@
import sys
from setuptools import setup
-
def read(*parts):
- return codecs.open(os.path.join(os.path.abspath(os.path.dirname(__file__)), *parts), 'r').read()
-
+ with codecs.open(os.path.join(os.path.abspath(os.path.dirname(__file__)), *parts), 'r') as f:
+ return f.read()
def find_version(*file_paths):
version_file = read(*file_paths) I'll have to unpatch to see that actual error was. |
I had this happen a lot when installing pip as part of a virtualenv creation - I always put it down to virus checkers temporarily holding some file open (mainly because it was intermittent). But this may be the real reason. I'll try testing on my slow machine with the virus checker tomorrow, and see if I can reproduce the original issue, and if so, whether this patch fixes it. I'll report back tomorrow... |
if you are dealing with virtualenv, you might have to pactch the tarball that virtualenv installs pip from. site-packages\virtualenv_support\pip...tar.gz |
Never mind, when I try to reproduce the issue I had, I can't. I suspect it wasn't pip-related anyway (IIRC, distribute's setup process was also an issue). Having said that, I don't have a problem with the setup.py patch. It's clearly "more correct" than the original code. Although you need to add a |
I found my original error. It was on installing pip on pypy under virtualenv\win32 (doing test environments). When distribute cleaned up the working directory files were still open. So this isn't exactly related to this bug, sorry. I was in the process of submitting from a list of bugs\patches to a group of projects and was looking for already submitted issues. But if you all want the patch I can fix it and submit, just let me know where to shoot: Here, a new issue, pull request, etc. |
I realize this is an older issue, but this problem is still persisting. I've isolated it to here. This In my case I have some corporate anti-virus that consistently holds files open long enough to make nearly every pip install fail. I tried changing I was able to get past this by using I'll submit a PR for either desired option of fixing the issue. Granted, I realize it's not an issue everyone will have, but this change also wouldn't negatively affect anyone else. |
It should likely use |
That's what I was using. |
What's needed here is something similar that, when it hits an error, waits for a short while (I have no idea how long is reasonable, depends on how the virus checker works) and then retries the delete. Whether we loop if the retry fails (risking an infinite wait for a genuinely undeletable file) or ignore errors on the retry (risking leaving junk lying around) is an open question. Simplest answer, though, is just to ignore errors as suggested by the OP. This will leave junk around in the face of a virus checker as described, but at least it won't fail. Why is it that virus checkers seem to cause far more problems than the viruses they are supposed to be protecting us again? :-( |
Perhaps we should do something like https://pypi.python.org/pypi/retrying in |
I wouldn't be opposed to ignoring and logging or waiting and retrying. It just kinda needs something. |
Note that so far there have been three scenarios reported as causing it to happen:
Of these, two (2 and 3) are temporary and waiting will likely resolve the issue. The third (open in a window) I suspect is an instance of the more general "something is using the directory as the cwd" which won't go away until that process completes (and it can happen that a persistent background process ends up with the directory as cwd, meaning it won't go away till a reboot). But really, why are people messing round in the build directory while the build is running? (They do, though, so we need to cater for it). Also, there are possibly multiple places this matters. @zephraph pointed at where we download a HTTP URL to a temporary directory. The original report was about build directories (which is likely in the I'm inclined to suggest that we enhance
If the deletion fails at this point, and ignore_errors is set, log a visible warning message to the user [2]. Otherwise let the error propagate to the caller. Notes: |
The retrying thing can handle the retries, it's a nice little wrapper that, if an exception is raised, will simply retry the operation. You can specify a maximium number of retries, or a maximum amount of time, and you can do a backoff factor so it retries quickly and then retries again waiting longer. |
Yeah, I get this. It looks quite nice (were you proposing vendoring it, or writing our own? I assume the former). I wasn't 100% sure where you intended to apply it - to |
In my case using I'd vote for the retry decorator using the back-off factor with a total time of no more than 3 seconds. That way the majority of cases would be caught in the first, fast few tries and there's a longer period for any funky happenings. |
Yea I'd just vendor it assuming it works on 2.6+ and 3.2+. No reason to write our own if we can help it. I also think just applying it to rmtree makes sense. I can't think of a situation where we want to delete a directory, but only want to delete it if we can the first time. I'm not sure what happens if you pass a non-existent directory to rmtree, but it's possible that it will need to be made to count that as a "success". |
@zephraph Yeah, but |
While that technically fixes the problem, it still probably isn't the most graceful way to handle things. I'm in agreement with the above conversation which follows these steps:
|
Well, in my opinion, for a small problem use a small solution. I dont know .rmtree, but if something locked, and you ignore errors you get the same result!? |
I'm getting this error every time i try to install a new package via pip. It's never happened on this machine before - I suspect it's due to antivirus (Panda) keeping a hold on the newly created dir. |
That's very likely the case. I've somewhat abandoned python at work until I can get time to fix this or someone else fixes it. |
OK, I've created PR #2397 for this. It needs tweaking to tune the retry behaviour (at the moment, it just retries a few times with no delays, which isn't much good). I'll work on that in a while. @dstufft could you check my vendoring of I haven't done anything yet about places that don't currently use |
Closed via #2397 |
@pfmoore Thanks Paul that fixed it. |
Looks like this was closed, but I'm still experiencing the issue. Two times today I've attempted to install something using pip, and got a message about a directory not being empty. When retrying pip states "Requirements already satisfied," but I'm not sure whether to trust my installation now. If the error happened during cleanup then I can live with temp files not being cleared, but it's hard to say where in the install it happened. Any tips would be appreciated. Sorry for the messed up formatting, due to cmd width limits:
During handling of the above exception, another exception occurred: Traceback (most recent call last): |
Sorry, rather than reopening this old thread I thought it would be prudent to just open a new issue: #4734 |
I was trying to install lot many packages with pip(on Windows) and sometimes(only "sometimes") I get the below error.
File "my_hudson_workspace_path\lib\site-packages\pip-1.0-py2.6.egg\pip\basecommand.py", line 126, in main
self.run(options, args)
File "my_hudson_workspace_path\lib\site-packages\pip-1.0-py2.6.egg\pip\commands\install.py", line 228, in run
requirement_set.install(install_options, global_options)
File "my_hudson_workspace_path\lib\site-packages\pip-1.0-py2.6.egg\pip\req.py", line 1102, in install
requirement.remove_temporary_source()
File "my_hudson_workspace_path\lib\site-packages\pip-1.0-py2.6.egg\pip\req.py", line 610, in remove_temporary_source
rmtree(self._temp_build_dir)
File "my_hudson_workspace_path\lib\site-packages\pip-1.0-py2.6.egg\pip\util.py", line 29, in rmtree
onerror=rmtree_errorhandler)
File "c:\Python26\Lib\shutil.py", line 216, in rmtree
rmtree(fullname, ignore_errors, onerror)
File "c:\Python26\Lib\shutil.py", line 216, in rmtree
rmtree(fullname, ignore_errors, onerror)
File "c:\Python26\Lib\shutil.py", line 216, in rmtree
rmtree(fullname, ignore_errors, onerror)
File "c:\Python26\Lib\shutil.py", line 216, in rmtree
rmtree(fullname, ignore_errors, onerror)
File "c:\Python26\Lib\shutil.py", line 216, in rmtree
rmtree(fullname, ignore_errors, onerror)
File "c:\Python26\Lib\shutil.py", line 225, in rmtree
onerror(os.rmdir, path, sys.exc_info())
File "c:\Python26\Lib\shutil.py", line 223, in rmtree
os.rmdir(path)
WindowsError: [Error 145] The directory is not empty: 'e:\temp\pip-sr1bjf-build\build\Pygments\tests\examplefiles\output'
Same error is coming with a few different packages also:
WindowsError: [Error 145] The directory is not empty: 'e:\temp\pip-cor26d-build\build\pytz\pytz\zoneinfo\Africa
WindowsError: [Error 145] The directory is not empty: 'e:\temp\pip-tyqd6c-build\build\SQLAlchemy\doc\build\templates'
Is this an issue with Pip or something related to my environment.
The text was updated successfully, but these errors were encountered: