uv: uv pip install inconsistent failure on Windows
- Windows 22H2
- Using PowerShell env (in either Windows Terminal or powershell.exe, non-elevated)
When using uv pip install -r requirements.txt, I will frequently get the following error:
error: Failed to download distributions
Caused by: Failed to fetch wheel: setproctitle==1.3.3
Caused by: Failed to read from the distribution cache
Caused by: failed to rename file from \\?\C:\Users\[____]\AppData\Local\Temp\1\.tmp56ZHLz\.tmpMXOwQn to \\?\C:\Users\[____]\AppData\Local\Temp\1\.tmp56ZHLz\archive-v0\7RXhEx7TcTNKRTlP3vSED
Caused by: Access is denied. (os error 5)
This appears to be independent of the package, though seemingly happens more often with some than others.
If run with --no-cache, it’s almost impossible to install, as at least one thing is likely to fail in the process and progress restarted.
If run without --no-cache, retrying a number of times will eventually succeed (however, it will leave .tmp[_______] folders listed in the error messages in C:\Users\[____]\AppData\Local\uv\cache).
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 6
- Comments: 77 (37 by maintainers)
Commits related to this issue
- Add backoff for transient Windows failures (#2419) ## Summary This may be required elsewhere, but all the traces in that issue are related to persisting the temporary directory to our persistent ... — committed to astral-sh/uv by charliermarsh 3 years ago
- Retry on spurious failures when caching built wheels (#4605) https://github.com/astral-sh/uv/pull/2419 appears to have only applied this retry to wheels that were already downloaded (though I would ... — committed to astral-sh/uv by zanieb 2 years ago
- Retry on permission errors when persisting extracted source distributions to the cache (#5076) Another case for https://github.com/astral-sh/uv/issues/1491 ref #4606 — committed to astral-sh/uv by zanieb 2 years ago
Definitely want to fix this.
Never saw this kind of responsiveness in a project, respect! 🥇
The \\?\ prefix is just a way around the MAX_PATH (256 char) limitation in Windows API calls. I’d personally be surprised if it had an impact although I couldn’t say for sure.
Having dealt with similar issues in other projects where Windows antivirus software is holding file locks after any file system operations, the best solution is usually just to retry the operation on failure a handful of times with a slightly increasing sleep in between attempts unfortunately.
Ah, this is consistent with the experience in the first post.
I think this issue may crop up in corporate or more secure environments that have some layer of security running over all processes. I think there is a slight lag between when uv unzips the files where that process is ran in a sandbox and there is a slight delay before the os will allow access to the resulting folder while its scanned, I think simply catching the “os error” and retrying with some timeout would prevent this error on systems that have some security layer that temporarily effects permissions and also why a package like numpy (big and many small files) would consistently trip and medium packages would occasionally go through and occasionally trip.
i.e. you may not be able to re-produce this error in dev without setting up a test box that use one of these paid corporate security software to trigger it. You generally only create windows binaries on tagged releases, if you can create a dev build binary I can test it on my system
Do you mind opening a separate issue with more details? That sounds like a bug (as opposed to a spurious failure).On Jul 24, 2024, at 7:46 AM, Pavel Dikov @.***> wrote: Clearly separate from the root cause here but since it’s mentioned here:
I’m open to changing to use the dunce-canonicalized version everywhere, but note that it doesn’t, like, fully solve the problem (if it is a problem). dunce will still return a UNC prefix if the path is longer than 260 characters.
@charliermarsh are you still open to this change? We’re hitting this problem with pyvenv.cfg (the home path in particular) – importing dynamic libraries from UNC-prefixed paths fails miserably for at least some Python versions. Happy to open another issue.
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: @.***>
I stress-tested
v0.2.25on our windows CI by focussing on source distributions only. They all passed and instead of failing because files in the cache can’t be renamed, I finally see retrying warnings like these:🎉 Thanks a lot for your effort!
Looks like @zanieb already pushed a PR and may have found a fix, but should it be useful, here’s the IO activity of the thread from https://github.com/astral-sh/uv/issues/1491#issuecomment-2228830850
Hi,
the latest version (
uv 0.2.15 (bfc342da9 2024-06-24)) still has these issues. We see this on a certain percentage every on our Windows CI runners. They do haveCrowdStrikemessing with our workloads unfortunately - corporate policy 😢The common denominator seems to be source distributions which
uvtries to build wheels from. I’ve never seen this error for packages that are available as wheel.Hypothesis: snakeoil scanners need more time to scan compressed archives (because of the decompression step) and
uvs backoff algorithm just needs a little tweaking to accommodate for that.A few source distribution only packages:
fire,odfpy,mapdata,pywinusbA bunch of error messages for these packages
This will take some trial and error. I’ll add some improvements in the next release, and then look to folks in this thread for testing.
Oh, yes, happy if this is handled by uv
I just don’t want to write a bash script on my end to retry the installation till it works
I think the effect on speed would be imperceptible to the end user. The uv speed up is more to do with dependency resolution and retrying is to deal with likely milliseconds of time that a security layer on Windows locks access to the extracted zip contents before uv can read and copy the data from the tmp folder to the archive
The overall approach is: unzip into a temporary folder, then move that folder into the cache to persist it. (This avoids persisting incomplete downloads that may error partway through.)
Just to add some more context to this, I get the same error and it will fail on different packages on each attempt if running uv clean in between
I suspect something in the temp file naming is randomly causing issues and after I tried 5 times with “uv clean” in-between it finished but it is happening frequently enough that there is a real issue. I am using the latest uv release 0.15 at the time of posting this issue
That appears to be a different error. This isn’t about the particular package
distributions. This appears to be very specifically just an error somewhere in the renaming of folders.Just tried using a requirements file off the shelf: https://github.com/google-research/kubric/blob/main/requirements.txt
I’ve added the full log including retries this time, showing how it’s not always the same package, and retries will eventually succeed. (Also generating 300+MB of trash in the leftover
.tmp[______]folders inC:\Users\[____]\AppData\Local\uv\cache)Subsequent installs are fine after the first install (and fast!), as everything is already in the cache.
Contrasted with regular Python pip, which installs first try, with or without cache.