Title: py Launcher for Windows with MSYS2
Type: behavior Stage: resolved
Components: Windows Versions: Python 3.10
Status: closed Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Zernoxi, eryksun, paul.moore, steve.dower, tim.golden, zach.ware
Priority: normal Keywords:

Created on 2021-12-06 16:56 by Zernoxi, last changed 2021-12-09 00:48 by Zernoxi. This issue is now closed.

Messages (13)
msg407840 - (view) Author: (Zernoxi) Date: 2021-12-06 16:56
Using "pyenv" for python installations. "py" launcher detects all installed python versions from "pyenv". When using the shebang feature, if the following shebang is specified, "#!/usr/bin/env python -V", it will detect python version of "3.9.9" from MSYS2 (where the latest version is "3.9.9"). But MSYS2 python is not in registered in registry so it should not be detecting it.
msg407842 - (view) Author: (Zernoxi) Date: 2021-12-06 17:10
This is not in a a virtual environment by the way.
msg407848 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2021-12-06 17:38
Are you launching "py" from inside MSYS2? Or a regular prompt?

What does the output of "py -0p" show? (It should list all the discovered installs)

We might need someone who understands how MSYS2 works here, because I don't.
msg407851 - (view) Author: (Zernoxi) Date: 2021-12-06 17:59
I am launching "py" from a regular prompt ("powershell"). I should only have 2 registered python versions in the registry. "py -0p" shows the correct information.

One thing to note is that if I "#!/usr/bin/env python3 -V", it will show the correct default python3 version and is consistence when in a virtual environment.
msg407856 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2021-12-06 19:03
So if I've understood you, there are three Python installs on your machine. Two of them are Windows builds, which are listed in the registry and discovered by py.exe -0p. The third is the MSYS2 build, which is *not* listed in the registry and is *not* discovered by py.exe -0p.

However, when you specify the shebang line "/usr/bin/env python" in a file and launch it as "py.exe" from a non-MSYS2 prompt, it launches the MSYS2 Python.

Is that correct?
msg407858 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2021-12-06 19:35
("2" and "3" are just arbitrary numbers... substitute however many Python runtimes you actually have, or "N" and "N+1" if you prefer.)
msg407862 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2021-12-06 20:53
The shebang "#!/usr/bin/env python" searches PATH for 
"python" plus the PATHEXT file extensions.

The shebang "#!/usr/bin/env python3" uses the highest version of Python 3 from the registry. It doesn't search PATH because Python installations do not necessarily include "python3.exe" or "python3.x.exe" binaries. Alternatives that also search PATH for this case have been discussed in prior issues.
msg407886 - (view) Author: (Zernoxi) Date: 2021-12-07 01:38
I did some more testing more testing some more testing and saw that eryksun pointed out that the PATH environment variable is also being checked. I thought that it only checked for registered pythons but anyway. If I remove the "bin" folder to MSYS2 then the issue goes away.
msg407887 - (view) Author: (Zernoxi) Date: 2021-12-07 01:56
Is there a way to "ignore" MSYS2 "bin" folder? Because "pyenv" is a wrapper for python versions and its python.exe is not explicitly in the PATH environment variable.
msg407888 - (view) Author: (Zernoxi) Date: 2021-12-07 02:05
My bad, I guess its not a bug. Didn't read the documents correctly.
msg407998 - (view) Author: (Zernoxi) Date: 2021-12-08 05:25
Is there a way to not parse certain paths in the PATH environment variable for the shebang: "#!/usr/bin/env python". I get that it is trying to mimic Unix "env" function but is it not conflicting if there is a python install but it is not registered in registry?
msg407999 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2021-12-08 06:31
You can use "#!python", or "#!/usr/bin/python", or "#!/usr/local/bin/python". They're all equivalent, and they do not search PATH. Since no wanted version is specified, the launcher will look for a version to run in the following order: an active virtual environment, a configured PY_PYTHON version, the highest registered version of 2.x, and the highest registered version of 3.x.
msg408060 - (view) Author: (Zernoxi) Date: 2021-12-09 00:48
True, that would work but it not ideal "Unix". I'll closed this since not unintended behavior.
Date User Action Args
2021-12-09 00:48:05Zernoxisetstatus: open -> closed

messages: + msg408060
stage: resolved
2021-12-08 06:31:44eryksunsetmessages: + msg407999
2021-12-08 05:25:28Zernoxisetmessages: + msg407998
2021-12-07 02:05:01Zernoxisetmessages: + msg407888
2021-12-07 01:56:41Zernoxisetmessages: + msg407887
2021-12-07 01:38:30Zernoxisetmessages: + msg407886
2021-12-06 20:53:26eryksunsetnosy: + eryksun
messages: + msg407862
2021-12-06 19:35:23steve.dowersetmessages: + msg407858
2021-12-06 19:03:30steve.dowersetmessages: + msg407856
2021-12-06 17:59:09Zernoxisetmessages: + msg407851
2021-12-06 17:38:56steve.dowersetmessages: + msg407848
2021-12-06 17:10:31Zernoxisetmessages: + msg407842
2021-12-06 16:56:27Zernoxicreate