astral-sh / uv

An extremely fast Python package and project manager, written in Rust.
https://docs.astral.sh/uv
Apache License 2.0
20.85k stars 616 forks source link

`uv init` hangs forever unless I add `--python-preference only-managed` #7667

Open will-henney opened 1 hour ago

will-henney commented 1 hour ago

Hi,

Just trying out uv for the first time (previous experience with rye), and weirdly I ran into problems running the first example command in the Getting Started docs:

$ uv -v init example
DEBUG uv 0.4.15
DEBUG Searching for default Python interpreter in managed installations or system path
DEBUG Searching for managed installations at `.local/share/uv/python`

and it just hangs forever until killed, using almost no CPU resources.

I guessed it was a problem with the search for pre-existing local python installations, so I tried it with

$ uv -v init example --python-preference only-managed

and that works fine.

System is macOS Sonoma 14.2.1 (23C71) running on intel

$ uv --version
uv 0.4.15 (0d81bfbc6 2024-09-21)

$ uname -a
Darwin gris.local 23.2.0 Darwin Kernel Version 23.2.0: Wed Nov 15 21:54:10 PST 2023; root:xnu-10002.61.3~2/RELEASE_X86_64 x86_64

Thanks

Will

zanieb commented 1 hour ago

That's really weird — can you share the output of RUST_LOG=uv=trace uv python find -v?

will-henney commented 42 minutes ago

So, now that I have run once with only-managed it seems to be working fine even without that flag. I get

$ RUST_LOG=uv=trace uv python find -v
DEBUG uv 0.4.15
DEBUG Searching for default Python interpreter in managed installations or system path
DEBUG Searching for managed installations at `/Users/will/.local/share/uv/python`
DEBUG Found managed installation `cpython-3.12.6-macos-x86_64-none`
TRACE Cached interpreter info for Python 3.12.6, skipping probing: /Users/will/.local/share/uv/python/cpython-3.12.6-macos-x86_64-none/bin/python3
DEBUG Found `cpython-3.12.6-macos-x86_64-none` at `/Users/will/.local/share/uv/python/cpython-3.12.6-macos-x86_64-none/bin/python3` (managed installations)
/Users/will/.local/share/uv/python/cpython-3.12.6-macos-x86_64-none/bin/python3

However, if I try and get back to the initial conditions after installing uv for the first time by nuking .local/share/uv, then I can reproduce the hanging behavior:

$ rm -r ~/.local/share/uv
$ RUST_LOG=uv=trace uv python find -v
DEBUG uv 0.4.15
DEBUG Searching for default Python interpreter in managed installations or system path
DEBUG Searching for managed installations at `/Users/will/.local/share/uv/python`
TRACE Searching PATH for executables: python3, python
TRACE Checking `PATH` directory for interpreters: /Users/will/.cargo/bin
TRACE Checking `PATH` directory for interpreters: /Users/will/.gem/ruby/2.6.0/bin
TRACE Checking `PATH` directory for interpreters: /Users/will/mambaforge/condabin
TRACE Checking `PATH` directory for interpreters: /Users/will/.rye/shims
TRACE Found possible Python executable: /Users/will/.rye/shims/python3
TRACE Querying interpreter executable at /Users/will/.rye/shims/python3
^C

So it looks like the problem might be with the rye-installed python. I will check this next

zanieb commented 35 minutes ago

I wonder if the Rye shim is invoking uv so it cycles?