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 fails to find python in non-venv install on Windows #1779

Closed
gaborbernat opened this issue Feb 20, 2024 · 11 comments · Fixed by #2000
Closed

uv fails to find python in non-venv install on Windows #1779

gaborbernat opened this issue Feb 20, 2024 · 11 comments · Fixed by #2000
Assignees
Labels
windows Specific to the Windows platform

Comments

@gaborbernat
Copy link
Contributor

When trying to run the tool on Windows, I get this rust like stack trace:

Error: The system cannot find the file specified.
 (from CreateProcessA(null(), child_cmdline.into_bytes_with_nul().as_mut_ptr(),
    null(), null(), 1, 0, null(), null(), addr_of!(*si),
    child_process_info.as_mut_ptr()))

See https://github.com/tox-dev/tox-uv/actions/runs/7978647392/job/21784221224?pr=19

I'm using uv find_uv_bin...

@AlexWaygood
Copy link
Member

Interesting, this is the same error I was getting in #1639 (cc. @MichaReiser)

@AlexWaygood
Copy link
Member

AlexWaygood commented Feb 20, 2024

Have you created and activated a virtual environment? My and Micha's conclusion from debugging #1639 was that it's not possible on Windows (yet) to use the "trick" where you pretend a virtual environment has been created and activated by doing the echo "VIRTUAL_ENV=${Python_ROOT_DIR}" >> $GITHUB_ENV in a GitHub Actions workflow. The reason why this doesn't work on Windows is likely due to the fact that python.exe is found in a different directory on Windows when a virtual environment hasn't been activated (it's not in a Scripts/ directory when a virtual environment hasn't been activated, and uv assumes python.exe will always be in a Scripts/ directory on Windows). So the VIRTUAL_ENV trick to avoid having to create and activate an environment currently only works on Unix.

(Edit: it looks like you are indeed doing the Unix-only "trick": https://github.com/tox-dev/tox-uv/blob/a93e37e98a012d07d6ac151e097c444a77d15b0a/.github/workflows/check.yml#L43)

@AlexWaygood
Copy link
Member

I outlined a cross-platform way of using uv in a GitHub Actions workflow here: #1386 (comment)

@gaborbernat
Copy link
Contributor Author

Yeah, I can do that, but sounds more like a workaround than a solution for the underlying problem 👍

@AlexWaygood
Copy link
Member

AlexWaygood commented Feb 20, 2024

Yeah, I can do that, but sounds more like a workaround than a solution for the underlying problem 👍

Oh of course. Longer-term we want to have first-class support for GitHub Actions, which I think will probably include something like #1526. We absolutely agree the current situation is far from ideal :)

@zanieb zanieb added the question Asking for clarification or support label Feb 21, 2024
@MichaReiser MichaReiser added the windows Specific to the Windows platform label Feb 21, 2024
@MichaReiser MichaReiser self-assigned this Feb 21, 2024
@MichaReiser MichaReiser removed their assignment Feb 21, 2024
@jenshnielsen
Copy link

I ran into this error when trying to run pytest installed with uv from a pre existing conda environment.

@MichaReiser
Copy link
Member

MichaReiser commented Feb 22, 2024

The main issue here is that uv assumes that Python is located at $VIRTUAL_ENV/Scripts/python.exe which isn't the case when pointing to a global python installation. see #1803 for some details.

@jenshnielsen #1803 might help with your issue, depending on the layout of the venv directory

@MichaReiser MichaReiser removed their assignment Feb 22, 2024
@konstin konstin changed the title uv crashes on Windows with The system cannot find the file specified uv fails to find python in non-venv install Feb 22, 2024
@konstin konstin removed the question Asking for clarification or support label Feb 22, 2024
@AlexWaygood AlexWaygood changed the title uv fails to find python in non-venv install uv fails to find python in non-venv install on Windows Feb 22, 2024
@Pixel-Minions
Copy link

I wonder of this is related to the same issue I am having with embedded versions of Python:
#1656

@mkleinbort
Copy link

Is a solution for this in the works? I'm preparing an internal talk on UV for users that use windows and keen to know what they should expect.

@MichaReiser
Copy link
Member

We're planning to solve this as part of #1526

The recommended local workflow is to use a venv instead of installing dependencies globally.

@charliermarsh charliermarsh self-assigned this Feb 26, 2024
@charliermarsh
Copy link
Member

Yup I'm on it.

charliermarsh added a commit that referenced this issue Feb 28, 2024
…erpreters (#2000)

## Summary

This PR adds a `--python` flag that allows users to provide a specific
Python interpreter into which `uv` should install packages. This would
replace the `VIRTUAL_ENV=` workaround that folks have been using to
install into arbitrary, system environments, while _also_ actually being
correct for installing into non-virtual environments, where the bin and
site-packages paths can differ.

The approach taken here is to use `sysconfig.get_paths()` to get the
correct paths from the interpreter, and then use those for determining
the `bin` and `site-packages` directories, rather than constructing them
based on hard-coded expectations for each platform.

Closes #1396.

Closes #1779.

Closes #1988.

## Test Plan

- Verified that, on my Windows machine, I was able to install `requests`
into a global environment with: `cargo run pip install requests --python
'C:\\Users\\crmarsh\\AppData\\Local\\Programs\\Python\\Python3.12\\python.exe`,
then `python` and `import requests`.
- Verified that, on macOS, I was able to install `requests` into a
global environment installed via Homebrew with: `cargo run pip install
requests --python $(which python3.8)`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
windows Specific to the Windows platform
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants