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

--system doesn't work on Windows on Python <3.12 in GitHub Actions #2056

Closed
AlexWaygood opened this issue Feb 28, 2024 · 14 comments · Fixed by #2057
Closed

--system doesn't work on Windows on Python <3.12 in GitHub Actions #2056

AlexWaygood opened this issue Feb 28, 2024 · 14 comments · Fixed by #2057
Assignees
Labels
bug Something isn't working windows Specific to the Windows platform

Comments

@AlexWaygood
Copy link
Member

See AlexWaygood/typeshed-stats#200 for a repro. It's possible this is a just-in-GitHub Actions thing.

@AlexWaygood AlexWaygood added bug Something isn't working windows Specific to the Windows platform labels Feb 28, 2024
@charliermarsh charliermarsh self-assigned this Feb 28, 2024
@AlexWaygood
Copy link
Member Author

AlexWaygood commented Feb 28, 2024

It appears to work fine on Python 3.12, but on Python 3.11/3.10 in CI, running coverage -m pytest leads to this error message (despite coverage and pytest having both been installed by uv using --system):

coverage: D:\a\_temp\2100b3f7-7035-42ca-a241-f5034d096de8.ps1:2
Line |
   2 |  coverage run -m pytest --doctest-modules
     |  ~~~~~~~~
     | The term 'coverage' is not recognized as a name of a cmdlet, function, script file, or executable program. Check
     | the spelling of the name, or if a path was included, verify that the path is correct and try again.
Error: Process completed with exit code 1.

@charliermarsh
Copy link
Member

I've confirmed that this works as expected locally. If I install Python 3.10 from python.org, I can globally install binaries like isort, and they get picked up in my PATH.

@AlexWaygood AlexWaygood changed the title --system doesn't work on Windows on Python <3.12 --system doesn't work on Windows on Python <3.12 in GitHub Actions Feb 28, 2024
@charliermarsh
Copy link
Member

It looks like the problem is that --system is installing into Python 3.12 (which is already installed in the image, I assume?) rather than the version installed via the setup action.

@charliermarsh
Copy link
Member

The problem is that we first look in py --list-paths, and that returns:

-V:3.12 *        C:\hostedtoolcache\windows\Python\3.12.2\x64\python.exe
-V:3.12-32       C:\hostedtoolcache\windows\Python\3.12.2\x86\python.exe
-V:3.11          C:\hostedtoolcache\windows\Python\3.11.8\x64\python.exe
-V:3.11-32       C:\hostedtoolcache\windows\Python\3.11.8\x86\python.exe
-V:3.10          C:\hostedtoolcache\windows\Python\3.10.11\x64\python.exe
-V:3.10-32       C:\hostedtoolcache\windows\Python\3.10.11\x86\python.exe
-V:3.9           C:\hostedtoolcache\windows\Python\3.9.13\x64\python.exe
-V:3.9-32        C:\hostedtoolcache\windows\Python\3.9.13\x86\python.exe
-V:3.8           C:\hostedtoolcache\windows\Python\3.8.10\x64\python.exe
-V:3.8-32        C:\hostedtoolcache\windows\Python\3.8.10\x86\python.exe
-V:3.7           C:\hostedtoolcache\windows\Python\3.7.9\x64\python.exe
-V:3.7-32        C:\hostedtoolcache\windows\Python\3.7.9\x86\python.exe

So that ends up returning the Python 3.12.2 interpreter that comes pre-bundled in the cache.

@charliermarsh
Copy link
Member

I'm not sure how to fix this. Should we be looking in PATH first? \cc @konstin

@ofek
Copy link
Contributor

ofek commented Feb 29, 2024

Yes, please look in PATH first as in the majority of scenarios the py launcher will not be used or even available (as I was trying to express in the other issue).

@charliermarsh
Copy link
Member

There's a PR open for it here: #2057.

@charliermarsh
Copy link
Member

Do you have a link to the other issue? I'd like to read (but was focused on other things at the time).

@ofek
Copy link
Contributor

ofek commented Feb 29, 2024

#1310 (comment)

@charliermarsh
Copy link
Member

I know you mention this in your comment but I'm surprised because virtualenv does seem to do registry-based lookups before PATH.

@ofek
Copy link
Contributor

ofek commented Feb 29, 2024

Nothing will be added to one's registry without an installer that does that. So for example if you build from source or use a prebuilt distribution and merely unpack then you have to just rely on PATH.

@konstin
Copy link
Member

konstin commented Feb 29, 2024

When installing the defaults from the official build from python.org build, you get the py launcher but no PATH modification. This means that the great majority of users - especially those who don't have expertise around PATH - will have no python.exe in PATH

Python 3.12 installer

Above is the preset configuration.

@ofek
Copy link
Contributor

ofek commented Feb 29, 2024

Yes, that is true. However almost everyone enables that checkbox to add to PATH because you only install with that GUI if you're an average user and the vast majority of folks have no idea about the registry PEP (why would they) so in order to make it usable you check the box not even so much for external tools but so you have a python available on the command line. So, that group will always have PATH updated.

The other, far far larger group, will install Python on servers. In this case they will disable the py launcher because it's irrelevant or not even have it because they are building from source to get optimizations, either themselves or fetching some prebuilt distribution to unpack.

I have been exclusively a Windows user my entire life. I cannot express enough how few people use the py launcher and how often the registry stuff is unused.

In the official documentation, their example updates PATH https://docs.python.org/3/using/windows.html#installing-without-ui:

python-3.9.0.exe /quiet InstallAllUsers=1 PrependPath=1 Include_test=0

You will be hard-pressed to find code on GitHub (and in private) that does not rely on PATH. Some examples:

@AlexWaygood
Copy link
Member Author

Yeah, having been exclusively a Windows user until very recently, I agree with basically everything @ofek is saying here

charliermarsh added a commit that referenced this issue Feb 29, 2024
`uv --system` is failing in GitHub Actions, because `py --list-paths`
returns all the pre-cached Pythons:

```
-V:3.12 *        C:\hostedtoolcache\windows\Python\3.12.2\x64\python.exe
-V:3.12-32       C:\hostedtoolcache\windows\Python\3.12.2\x86\python.exe
-V:3.11          C:\hostedtoolcache\windows\Python\3.11.8\x64\python.exe
-V:3.11-32       C:\hostedtoolcache\windows\Python\3.11.8\x86\python.exe
-V:3.10          C:\hostedtoolcache\windows\Python\3.10.11\x64\python.exe
-V:3.10-32       C:\hostedtoolcache\windows\Python\3.10.11\x86\python.exe
-V:3.9           C:\hostedtoolcache\windows\Python\3.9.13\x64\python.exe
-V:3.9-32        C:\hostedtoolcache\windows\Python\3.9.13\x86\python.exe
-V:3.8           C:\hostedtoolcache\windows\Python\3.8.10\x64\python.exe
-V:3.8-32        C:\hostedtoolcache\windows\Python\3.8.10\x86\python.exe
-V:3.7           C:\hostedtoolcache\windows\Python\3.7.9\x64\python.exe
-V:3.7-32        C:\hostedtoolcache\windows\Python\3.7.9\x86\python.exe
```

So, our default selector returns the first entry here. But none of these
are actually in `PATH` except the one that the user installed via
`actions/setup-python@v5` -- that's the point of the action, that it
puts the correct versions in `PATH`.

It seems to me like we should prioritize `PATH` over `py --list-paths`.
Is there a good reason not to do this?

Closes: #2056
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

Successfully merging a pull request may close this issue.

4 participants