On 1/15/2024 1:26 PM, Mats Wichmann via Python-list wrote:
On 1/15/24 09:44, Sibylle Koczian via Python-list wrote:
First and foremost I want to understand why I'm seeing this:
- Python scripts with "/usr/bin/env python3" as shebang line work as
expected on a computer with Windows 10 and Python 3.11.5. They have
worked for years on this machine, using either the latest Python or
one version before (depending on availability of some packages). There
is a virtual machine with ArchLinux on the same machine and some of
the scripts are copies from that.
- I've got a second computer with Windows 11 and I installed Python
3.12.1 on it. After copying some scripts from my first computer I
found that I couldn't start them: not by entering the script name in a
console, not using py.exe, not double clicking in the explorer.
Entering <full_path_to_python.exe>\python <scriptname> probably worked
- I think I tried that too, but I'm not really sure, because that's
really not practical.
In the Python documentation for versions 3.11 and 3.12 I found no
differences regarding py.exe and shebang lines.
Then I removed the "/env" from the shebang lines and could start the
scripts from the second computer. That certainly is a solution, but
why???
It's because of Windows itself. The default nowadays is that irritating
little stub that prompts you to go install Python from the WIndows
store. When you use the "env" form, it looks for python (or python3 in
your case) in the PATH *first* and you'll get a hit. Mine looks like:
C:\Users\mats\AppData\Local\Microsoft\WindwsApps\python.exe and python3.exe
you can check what it's doing for you by using the "where" command in a
windows shell.
On your older Windows 10 machine you either never had that stub - I
don't know when it was added, maybe someone from Microsoft listening
here knows - or it's been superseded by changes to the PATH, or
something. On my fairly new Win 11 box the base of that path is early
in the user portion of PATH, so that must be a default.
py.exe without the "/usr/bin/env" magic doesn't put PATH searching
first, according to that snip from the docs that's been posted here
several times., so you shouldn't fall down that particular rathole.
Python from the App Store is not the same as Python from python.org:
"The Microsoft Store package is a simple installation of Python that is
suitable for running scripts and packages, and using IDLE or other
development environments. It requires Windows 10 and above, but can be
safely installed without corrupting other programs. It also provides
many convenient commands for launching Python and its tools."
- https://docs.python.org/3/using/windows.html
Also:
"The Windows Store distribution of Python is a sandboxed application ...
The internal components of Windows Store apps are protected from being
accessed from other applications, and so the PyXLL add-in cannot use the
Python DLLs and packages that are installed as part of the Windows Store
Python app."
From the PyXLL support site -
https://support.pyxll.com/hc/en-gb/articles/4417634326675-Python-installed-via-the-Windows-Store-cannot-be-used-with-PyXLL
The "py" launcher is installed by the installer from python.org.
--
https://mail.python.org/mailman/listinfo/python-list