Skip to content
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

uv python list fails if a pyenv-win install is included in the windows registry #6524

Closed
DavidCEllis opened this issue Aug 23, 2024 · 1 comment · Fixed by #6761
Closed
Assignees
Labels
bug Something isn't working help wanted Contribution especially encouraged uv python Related to the uv python interface windows Specific to the Windows platform

Comments

@DavidCEllis
Copy link

If a version of python is installed via pyenv with the --register flag then subsequently uv will fail to list python installs as it attempts to query metadata of a file that does not exist.

It looks like this is caused because uv makes the assumption that py --list-paths will return paths with only <major>.<minor> version information while pyenv installs are shown with <major>.<minor>.<micro>1. The regex is then capturing the <micro> part of the version as part of the path to the python executable.

static PY_LIST_PATHS: LazyLock<Regex> = LazyLock::new(|| {
// Without the `R` flag, paths have trailing \r
Regex::new(r"(?mR)^ -(?:V:)?(\d).(\d+)-?(?:arm)?\d*\s*\*?\s*(.*)$").unwrap()
});

Commands:

pyenv install 3.12.5 --register
uv python list

Full output:

C:\>uv --version
uv 0.3.2 (c5440001c 2024-08-23)

C:\>py --list
No installed Pythons found!

C:\>uv python list
cpython-3.12.5-windows-x86_64-none     <download available>
cpython-3.11.9-windows-x86_64-none     <download available>
cpython-3.10.14-windows-x86_64-none    <download available>
cpython-3.9.19-windows-x86_64-none     <download available>
cpython-3.8.19-windows-x86_64-none     <download available>
pypy-3.7.13-windows-x86_64-none        <download available>

C:\>pyenv install 3.12.5 --register
:: [Info] ::  Mirror: https://www.python.org/ftp/python
:: [Installing] ::  3.12.5 ...
:: [Info] :: completed! 3.12.5

C:\>py --list-paths
 -V:3.12.5 *      C:\Users\ducks\.pyenv\pyenv-win\versions\3.12.5\python.exe

C:\>uv python list
error: Failed to query Python interpreter
  Caused by: failed to query metadata of file `C:\.5 *      C:\Users\ducks\.pyenv\pyenv-win\versions\3.12.5\python.exe`
  Caused by: The filename, directory name, or volume label syntax is incorrect. (os error 123)

Example of py --list-paths output with multiple versions of python installed and registered with pyenv and some regular installs.2

 -V:3.13.0rc1 *   C:\Users\ducks\.pyenv\pyenv-win\versions\3.13.0rc1\python.exe
 -V:3.12.5        C:\Users\ducks\.pyenv\pyenv-win\versions\3.12.5\python.exe
 -V:3.12.5-win32  C:\Users\ducks\.pyenv\pyenv-win\versions\3.12.5-win32\python.exe
 -V:3.12          C:\Users\ducks\AppData\Local\Programs\Python\Python312\python.exe
 -V:3.12-32       C:\Users\ducks\AppData\Local\Programs\Python\Python312-32\python.exe
 -V:3.11.9        C:\Users\ducks\.pyenv\pyenv-win\versions\3.11.9\python.exe
 -V:3.10.11       C:\Users\ducks\.pyenv\pyenv-win\versions\3.10.11\python.exe
 -V:3.9.13        C:\Users\ducks\.pyenv\pyenv-win\versions\3.9.13\python.exe
 -V:3.8.10        C:\Users\ducks\.pyenv\pyenv-win\versions\3.8.10\python.exe

Footnotes

  1. It looks like py is just using the key names to get the version rather than the value of Version or SysVersion in the registry.

  2. This also lead to me finding out that pyenv-win registers 32bit python installs as 64bit which I've reported as a bug there.

@DavidCEllis DavidCEllis changed the title 'uv python list' fails if a pyenv-win install is included in the windows registry uv python list fails if a pyenv-win install is included in the windows registry Aug 23, 2024
@charliermarsh charliermarsh added bug Something isn't working help wanted Contribution especially encouraged windows Specific to the Windows platform labels Aug 23, 2024
@charliermarsh
Copy link
Member

Thank you!

@zanieb zanieb added the uv python Related to the uv python interface label Aug 23, 2024
@konstin konstin self-assigned this Aug 28, 2024
konstin added a commit that referenced this issue Aug 28, 2024
Our current strategy of parsing the output of `py --list-paths` to get the installed python versions on windows is brittle (#6524, missing `py`, etc.) and it's slow (10ms last time i measured).

Instead, we should behave spec-compliant and read the python versions from the registry following PEP 514.

We're using the official rust-for-windows crates for accessing the registry.

Fixes #1521
Fixes #6524
konstin added a commit that referenced this issue Aug 28, 2024
Our current strategy of parsing the output of `py --list-paths` to get the installed python versions on windows is brittle (#6524, missing `py`, etc.) and it's slow (10ms last time i measured).

Instead, we should behave spec-compliant and read the python versions from the registry following PEP 514.

We're using the official rust-for-windows crates for accessing the registry.

Fixes #1521
Fixes #6524
konstin added a commit that referenced this issue Aug 28, 2024
Our current strategy of parsing the output of `py --list-paths` to get the installed python versions on windows is brittle (#6524, missing `py`, etc.) and it's slow (10ms last time i measured).

Instead, we should behave spec-compliant and read the python versions from the registry following PEP 514.

We're using the official rust-for-windows crates for accessing the registry.

Fixes #1521
Fixes #6524
konstin added a commit that referenced this issue Aug 29, 2024
Our current strategy of parsing the output of `py --list-paths` to get
the installed python versions on windows is brittle (#6524, missing
`py`, etc.) and it's slow (10ms last time i measured).

Instead, we should behave spec-compliant and read the python versions
from the registry following PEP 514.

It's not fully clear which errors we should ignore and which ones we
need to raise.

We're using the official rust-for-windows crates for accessing the
registry.

Fixes #1521
Fixes #6524
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Contribution especially encouraged uv python Related to the uv python interface windows Specific to the Windows platform
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants