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 venv: support Pythons installed via the Microsoft Store #2105

Closed
madig opened this issue Mar 1, 2024 · 8 comments
Closed

uv venv: support Pythons installed via the Microsoft Store #2105

madig opened this issue Mar 1, 2024 · 8 comments
Assignees
Labels
bug Something isn't working windows Specific to the Windows platform

Comments

@madig
Copy link

madig commented Mar 1, 2024

uv venv currently (v0.1.13) fails to create venvs with Pythons installed via the Microsoft Store (Windows 11 Version 10.0.22631 Build 22631). Example with Python 3.12:

❯ uv venv --verbose -p 3.12 vvv
 uv_interpreter::python_query::find_requested_python request=3.12
      0.003583s   0ms DEBUG uv_interpreter::python_query Starting interpreter discovery for Python @ `3.12`
      0.004400s   0ms DEBUG uv_interpreter::interpreter Cached interpreter info for Python 3.8.10, skipping probing: C:\Program Files\Python38\python.exe
      0.004961s   1ms DEBUG uv_interpreter::interpreter Cached interpreter info for Python 3.6.8, skipping probing: C:\Program Files\Python36\python.exe
      0.005404s   1ms DEBUG uv_interpreter::interpreter Probing interpreter info for: C:\Python27\python.exe
      0.062965s  59ms DEBUG uv_interpreter::python_query Found a Python 2 installation that isn't supported by uv, skipping.
      0.063666s  60ms DEBUG uv_interpreter::interpreter Probing interpreter info for: C:\Python27-64\python.exe
      0.114595s 111ms DEBUG uv_interpreter::python_query Found a Python 2 installation that isn't supported by uv, skipping.
  × failed to canonicalize path `C:\Users\...\AppData\Local\Microsoft\WindowsApps\python3.12.exe`
  ╰─▶ The file cannot be accessed by the system. (os error 1920)
@MichaReiser MichaReiser added the windows Specific to the Windows platform label Mar 1, 2024
@charliermarsh
Copy link
Member

Thanks!

@charliermarsh charliermarsh added the bug Something isn't working label Mar 1, 2024
@charliermarsh charliermarsh self-assigned this Mar 1, 2024
@NMertsch
Copy link

NMertsch commented Mar 1, 2024

Probably related:

  • Multiple Python versions installed via Microsoft Store (Win11, x64)
  • uv finds the requested Python version
  • copy-pasting the path from the uv error message works
  • sys.executable reports a different path
PS C:\Users\username> # try `uv venv`
PS C:\Users\username> uv venv --verbose --python 3.11
 uv_interpreter::python_query::find_requested_python request=3.11
      0.002206s   0ms DEBUG uv_interpreter::python_query Starting interpreter discovery for Python @ `3.11`
  × failed to canonicalize path `C:\Users\username\AppData\Local\Microsoft\WindowsApps\python3.11.exe`
  ╰─▶ The file cannot be accessed by the system. (os error 1920)
PS C:\Users\username> # execute python directly
PS C:\Users\username> C:\Users\username\AppData\Local\Microsoft\WindowsApps\python3.11.exe
Python 3.11.8 (tags/v3.11.8:db85d51, Feb  6 2024, 22:03:32) [MSC v.1937 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.executable
'C:\\Users\\username\\AppData\\Local\\Microsoft\\WindowsApps\\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\\python.exe'
>>>

@charliermarsh
Copy link
Member

Yeah I'm working on this now. Should work soon.

charliermarsh added a commit that referenced this issue Mar 3, 2024
## Summary

After #2121, the only remaining
issue is that calling `canonicalize` on these Pythons returns an error.

Closes #2105.

## Test Plan

Uninstalled all python.org Pythons on my Windows machine, then created a
virtualenv. The resulting config file:

```
Using Python 3.11.8 interpreter at: C:\Users\crmar\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\python.exe
Creating virtualenv at: .venv
Activate with: .venv\Scripts\activate
PS C:\Users\crmar\workspace\puffin> cat .\.venv\pyvenv.cfg
home = C:\Users\crmar\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0
implementation = CPython
version_info = 3.11.8
include-system-site-packages = false
uv = 0.1.13
prompt = puffin
```

Prior to this PR, it would fail with a canonicalization error.

Prior to #2121, it would leave a "bad" Python in the config file:

```
Using Python 3.11.8 interpreter at: C:\Users\crmar\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\python.exe
Creating virtualenv at: .venv
Activate with: .venv\Scripts\activate
PS C:\Users\crmar\workspace\puffin> cat .\.venv\pyvenv.cfg
home = C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.2288.0_x64__qbz5n2kfra8p0
implementation = CPython
version_info = 3.11.8
include-system-site-packages = false
uv = 0.1.13
prompt = puffin
```

Which, once activated, would fail with:

```
(venv) PS C:\Users\crmar\workspace\puffin> python
No Python at '"C:\Users\crmar\AppData\Local\Programs\Python\Python312\python.exe'
```
@madig
Copy link
Author

madig commented Mar 5, 2024

I'm not sure this is fixed?

AppData\Local\Temp
❯ uv --version
uv 0.1.14 (c525fdf2b 2024-03-04)

AppData\Local\Temp
❯ uv venv -p 3.12 vvv
  × failed to canonicalize path `C:\Users\...\AppData\Local\Microsoft\WindowsApps\python3.12.exe`
  ╰─▶ The file cannot be accessed by the system. (os error 1920)

@charliermarsh
Copy link
Member

It works without issue on my Windows Store installation. Do you mind sharing the outputs of import sys; print(sys.executable); print(sys._base_executable) on that installation?

@madig
Copy link
Author

madig commented Mar 5, 2024

❯ python3.12
Python 3.12.2 (tags/v3.12.2:6abddd9, Feb  6 2024, 21:26:36) [MSC v.1937 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys; print(sys.executable); print(sys._base_executable)
C:\Users\...\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\python.exe
C:\Users\...\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\python.exe

@charliermarsh
Copy link
Member

If I push to a branch, would you be able to test locally by running cargo build in the uv repo?

@charliermarsh
Copy link
Member

Creating a new issue for this specific fix (#2208), which I'm working on now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working windows Specific to the Windows platform
Projects
None yet
Development

No branches or pull requests

4 participants