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

Natively support py launcher on Windows #3520

Closed
2 tasks done
TBBle opened this issue Dec 31, 2020 · 6 comments
Closed
2 tasks done

Natively support py launcher on Windows #3520

TBBle opened this issue Dec 31, 2020 · 6 comments
Labels
kind/feature Feature requests/implementations status/triage This issue needs to be triaged

Comments

@TBBle
Copy link
Contributor

TBBle commented Dec 31, 2020

  • I have searched the issues of this repo and believe that this is not a duplicate.
  • I have searched the documentation and believe that my question is not covered.

Feature Request

poetry env use 3.9 is really nice, but assumes a binary named python3.9 is in the path.

On Windows, the Python installer does not install such version-named binaries, and so to avoid having multiple python.exe on the path, the py launcher is included, which is used by py -<version> exactly as Poetry is trying to do.

It would be nice if Poetry could correctly use this. I couldn't find a way to do this easily, as

poetry env use 'py -3.9'

tries to execute a binary named "py -3.9" (I suspect this is an intended regression due to fixing #1747), and without the quotes, it tries to take -3.9 as an option for itself, and fails.

As a workaround, I am, under PowerShell, doing this:

poetry env use $(py -3.8 -c 'import sys; print(sys.executable)')

which works fine.

Note that this isn't a problem for simply poetry install workflows, as it deafults to the Python with which Poetry is associated, and Poetry already knows the location of this binary. However, I hit this with a package that does not support Python 3.9, while I have Poetry installed under Python 3.9.

This problem also appears when trying to clean up venvs, as poetry env remove does not support "default Python" the way poetry install does.

poetry destroy was rejected in #926, so you can only clean up Poetry env by naming either the env's full name or the path to the Python binary; the latter requires the same workaround I'm using above.

@TBBle TBBle added kind/feature Feature requests/implementations status/triage This issue needs to be triaged labels Dec 31, 2020
sitd2813 referenced this issue in sitd2813/poetry Jun 26, 2021
sitd2813 referenced this issue in sitd2813/poetry Jun 29, 2021
@radoering
Copy link
Member

radoering commented Apr 11, 2022

I wonder if it might be better to use a lib that implements PEP-514 (e.g. pythonfinder) to find executables instead of using an application like py launcher?

Related-to: #2117

@TBBle
Copy link
Contributor Author

TBBle commented Apr 12, 2022

Yeah, that would make sense too, since py.exe has been rewritten in Python 3.11 as a PEP-514-consuming tool, so the results should be consistent.

@eyadmba
Copy link

eyadmba commented Feb 25, 2023

Any workaround for now?
Is there a way to switch the default python version for a session for example?

@absassi
Copy link

absassi commented Mar 13, 2023

@eyadmba the workaround is to specify the full path to the python.exe. It can be either the path to the one in the Python installation folder or the one in the Poetry environment, it doesn't matter. You can either use the following command, as indicated by @TBBle:

As a workaround, I am, under PowerShell, doing this:

poetry env use $(py -3.8 -c 'import sys; print(sys.executable)')

Or, if you have multiple environments already, one trick I sometimes do is to type poetry env info, copy the path, paste it in front of poetry env use and change the version number.

@TBBle
Copy link
Contributor Author

TBBle commented Mar 1, 2024

I'm closing this ticket in favour of #2117, since with Python 3.11's py consuming the PEP-514 data, I think it'd be better to consume that directly than try and wrap py or similar. #2117 is also a more problem-oriented ticket, this one lead with the solution.

It might be nice to have a way to make poetry env use 'py -3.9' work, i.e. be able to specify the Python binary and args for it, but that's a differently complex issue, and not Windows-specific.

@TBBle TBBle closed this as completed Mar 1, 2024
Copy link

github-actions bot commented Apr 1, 2024

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/feature Feature requests/implementations status/triage This issue needs to be triaged
Projects
None yet
4 participants