-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
poetry env use X.Y fails on Windows #2117
Comments
I've also been hit by this bug. Can this proposed solution be merged? |
same here, it has been over a year, seems still not been fixed... |
Not sure if we have to implement PEP 514 compliant searching by ourselves. It may be more sustainable to use an existing lib (e.g. pythonfinder). |
Duplicates #3520. |
Probably wrong. This issue is still valid. One could debate whether it is a bug or a missing feature (+ documentation bug). |
In my opinion this is a bug and it's still present on poetry 1.4.2. The introduction page says "It is multi-platform and the goal is to make it work equally well on Linux, macOS and Windows." It should be possible for Windows users to use the same commands. |
This still does not work on Windows on poetry 1.5.1 |
Same here, poetry 1.5.1, all python versions in Path, Windows10:
but this one is working:
|
I have exactly the same issue, its quite annoying to be honest. |
same issue here. Any progress on this one? currently on poetry 1.6.0 (Windows 11) |
I don't understand why This command...:
... gives this output on my machine:
It appears that
|
It seems to me that for |
It'd be interesting to know if the MS Store Python install is PEP 514-compliant.
And that also means we don't get bitten by systems that don't have |
I can't answer that. I don't have access to Microsoft Store, so I can't test it. Edit: Wrong conclusion below. PEP 514 search would work right now, also for my older Python installations. The problem described below is caused by pythonfinder not supporting PEP514 though it claims to do so.
|
Which version of My understanding of PEP 514 was that the registry keys used by So your results suggest either I misunderstood something in PEP 514, or there's a bug in Pythonfinder. The Pythonfinder docs use Python 3.7 as an example, so they think they support it. |
I think I am using the version, which came with Python 3.12.0. But I couldn't find a way to make it reveal its version, and it is installed in a separate directory. I just checked the registration database, and all my installed Python versions from 3.8 to 3.12 have the PEP 514 entries here: Computer\HKEY_CURRENT_USER\SOFTWARE\Python\PythonCore\ But I only have 3.11 and 3.12 in my path. So I wonder if Pythonfinder only uses the path, though it claims to use the registration database. |
I just had a quick look, and given I'm in a venv on a machine with only older Python installed, and no Python in my > py --list
Installed Pythons found by C:\WINDOWS\py.exe Launcher for Windows
(venv) *
-3.10-64
-3.9-64 I noticed that So if you're testing from inside a venv, that might override its use of PEP 514, but not searching the PATH? (Edit: That's probably "the running Python" being returned, rather than the venv's specifically... it makes sense that it'd always be detected when applicable, not sure if that can be disabled.) But seems like a pythonfinder-side issue, anyway. (Probably important since pipx-based Poetry usage would be in a venv, but needs to find other versions... pythonfinder might need to expose this as an option; the existing options on the Finder constructor didn't seem to make a difference.) Erk... Poking around, it looks like they dropped PEP 514 support in sarugaku/pythonfinder#135... I'm not sure if that was intentional, it looks like their test suite might have been relying on Python being in the path (or they're only testing with pyenv, not system-installed Python) and they didn't notice that they'd dropped PEP 514 support, since they didn't remove it from the docs or mention it in the PR. And sure enough, Anyway, 100% a bug on pythonfinder's side. I don't have time to lodge a bug report right now (it's 3am here...) so if you get a chance to do so, that'd be great. Edit: I also just noticed there's a pyfinder binary, but it fails to run as it appears to depend on > pip install --quiet --upgrade "pythonfinder[cli]<2" && pyfinder --findall
Found python at the following locations:
3.10: 3.10.11 (64bit) @ C:\Program Files\Python310\python.exe
3.9: 3.9.10 (64bit) @ C:\Program Files\Python39\python.exe
> pip install --quiet --upgrade "pythonfinder[cli]" && pyfinder --findall
ERROR: No valid python versions found! Check your path and try again.
Please provide a command
I also guess it doesn't see the running binary because it's not called Late edit: Lodged sarugaku/pythonfinder#158 for PEP-514 support being removed, and sarugaku/pythonfinder#159 for the CLI issues I found while investigating that. Alternative idea: Just directly use the module that pythonfinder used to use (https://github.com/zooba/pep514tools) to implement Late edit: I lean towards either using pep514tools directly, or just open-coding a PEP-514 consumer implementation; "Find a Python binary by that name in the registry" should be fairly simple. |
can we please merge this ffs? |
Merge what exactly? Also, please refrain from using foul language. |
People express their surprise in different ways. I agree that the previous poster's language was not optimal. And I agree that there is nothing to merge. With that said, some surprise is warranted. The status right now is:
I would create a pull request myself, but I haven't figured out from where in the poetry code I would need to call the function. The exception, which is shown to the user when X.Y is not found seems to originate from another part of the code than the one I would think was used by poetry env. So right now I am contemplating creating a pull request for a documentation update telling the user that the command is broken. |
Well, it is actually so simple that the code is in the very first post in this issue. Though with a hardcoded vendor name, which may not be the best approach. Anyway, I have also poked around. Here are my findings: The installer from python.org...:
Installing from Windows Store...:
I don't know if Microsoft Store will install the The command The command |
The command is not broken. Passing X.Y is just not supported on Windows. Passing a path to a python.exe works fine. In other words, a docs update is welcome but it will not be accepted if it says "the command is broken".
A solution would be nice for sure but the issue has not been important enough for anyone, perhaps because there is a simple workaround: just pass the path to the python.exe.
IIUC, Microsoft Store Python is not compliant with PEP 514. However, that does not matter because they create a pythonX.Y executable in a directory that is in the PATH. Originally, I said that it might make more sense to use a library like pythonfinder than to implement PEP 514 for ourselves. However, it looks like they dropped PEP 514 support (cf sarugaku/pythonfinder#158). In the meantime, I think it might make more sense to just implement it in Poetry. In case, you are interested in creating a PR, the relevant part in the code should be here: poetry/src/poetry/utils/env/env_manager.py Lines 177 to 188 in cab9c42
|
There is a plan to adopt |
|
@allanolesen there is |
Oops. Sorry for the confusion. |
Special care taken of python-poetry/poetry#2117
* Run unit tests with all supported Python versions. * Caching of Python deps in CI. Special care taken of python-poetry/poetry#2117 * Local action for DRY Python/Poetry install with caching.
this still seems to be broken in windows 11, any updates? |
I am on the latest Poetry version.
I have searched the issues of this repo and believe that this is not a duplicate.
If an exception occurs when executing a command, I executed it again in debug mode (
-vvv
option).OS version and name: Windows 10
Poetry version: 1.0.5
Link of a Gist with the contents of your pyproject.toml file: not needed
Issue
The shortcut command
poetry env use X.Y
to select the environment for Python X.Y, as documented in Managing environments, is broken in Windows. One is required instead to find, copy and paste the full path to Python executable.Note that the documentation even says "especially Windows where pyenv is not available".
The reason is quite simple: CPython installation in Windows doesn't provide
pythonX.Y.exe
, so even if you have all of them inPATH
, Poetry can only find the first one. They do, however, provide registry keys with installation locations, which Poetry can use to resolveX.Y
to the Python interpreter path.This piece of code should find the path to Python, given the version number as a
X.Y
string:I have adjusted the code above to make it compatible with Python 2, but I have not tested afterwards, so please forgive any mistakes.
The text was updated successfully, but these errors were encountered: