On 1/1/24 04:02, Sibylle Koczian via Python-list wrote:
Am 30.12.2023 um 04:04 schrieb Mike Dewhirst via Python-list:
I had assumed the OP had installed Python from the Microsoft shop and
that's where py.exe must have come from.
In fact I didn't say in my post that I always get Python from
python.org. When I started to use the language there was no Python from
any Microsoft shop (I'm not sure there was a Microsoft shop, it was in
the last millenium, Python 1.5 or 1.6). So I tend to forget that
possible download source.
But in all this thread I didn't see a single explanation for my current
situation: one and the same shebang line works on Windows 10 / Python
3.11 and doesn't work on Windows 11 / Python 3.12. I suspect Windows,
because a change in the way Python 3.12 uses shebang lines should be
visible in the documentation.
The shebang support in the Python Launcher is documented here:
https://docs.python.org/3/using/windows.html#shebang-lines
That says the line you list originally:
> My shebang line is usually "#!/usr/bin/env python3"
means look for python3 in PATH. Do you have one? If you don't have one,
you'll get one you don't want: the stupid Microsoft shim that, which if
run interactively, encourages you to install from the Microsoft store.
You should be able to disable this.
File suffix associations are a different thing - they give me no end of
headaches on Windows. They start out bound to the shim, and should
rebind to the launcher when you install, but then things can steal it.
If you install Visual Studio Code with Python extensions, then it takes
over the running of .py files - if you click in the explorer, you'll get
it open in the editor, not run. I've argued about this, to no avail
(plays havoc with my testsuite, which in some places tries to execute
Python scripts as a cli command).
And then I've got this:
C:\Users\mats\SOMEWHERE>py -0
-V:3.13 Python 3.13 (64-bit)
-V:3.12 * Python 3.12 (64-bit)
-V:3.11 Python 3.11 (64-bit)
-V:3.10 Python 3.10 (64-bit)
-V:3.9 Python 3.9 (64-bit)
-V:3.8 Python 3.8 (64-bit)
-V:3.7 Python 3.7 (64-bit)
-V:3.6 Python 3.6 (64-bit)
# Okay, it knows about lots of Python versions, and shows a default of 3.12
C:\Users\mats\SOMEWHERE>py
Python 3.12.1 (tags/v3.12.1:2305ca5, Dec 7 2023, 22:03:25) [MSC v.1937
64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> ^Z
# Great, that works just as expected
C:\Users\mats\SOMEWHERE>py test.py
Python was not found; run without arguments to install from the
Microsoft Store, or disable this shortcut from Settings > Manage App
Execution Aliases.
# wait, what? if "py" worked, why doesn't "py test.py"?
--
https://mail.python.org/mailman/listinfo/python-list