Mailing List Archive

Python 3.12.1, Windows 11: shebang line #!/usr/bin/env python3 doesn't work any more
Hello,

I always install Python on Windows in the same manner:

- Python is not on the path,
- it is installed for all users,
- the Python Launcher is installed for all users,
- the file types .py, .pyw etc. are associated with Python.

My shebang line is usually "#!/usr/bin/env python3".

This has always worked well. I could run Python scripts in a console
window entering just the script name, by double clicking in the explorer
or using WIN+r; the two last variants for GUI or for scripts with
something like "input('Leave with Enter')" at the end.

Now I've got a new computer with Windows 11 and I've installed Python
3.12.1. On my older machine it's Windows 10 and Python 3.11.5. Reading
the Python documentation it seems my shebang lines should work as before
- but they don't. The error message:

"Unable to create process using 'C:\usr\bin\env\python
"C:\Eigen\Src\launcher_versuche.py" ': Das System kann die angegebene
Datei nicht finden."

Without the "env" in the shebang line and only without it everything
works as expected - but that's contrary to the documentation, isn't it?

Thank you for information,
Sibylle
--
https://mail.python.org/mailman/listinfo/python-list
Re: Python 3.12.1, Windows 11: shebang line #!/usr/bin/env python3 doesn't work any more [ In reply to ]
> On 22 Dec 2023, at 12:39, Sibylle Koczian via Python-list <python-list@python.org> wrote:
>
> ?Hello,
>
> I always install Python on Windows in the same manner:
>
> - Python is not on the path,
> - it is installed for all users,
> - the Python Launcher is installed for all users,
> - the file types .py, .pyw etc. are associated with Python.
>
> My shebang line is usually "#!/usr/bin/env python3".
>
> This has always worked well. I could run Python scripts in a console
> window entering just the script name, by double clicking in the explorer
> or using WIN+r; the two last variants for GUI or for scripts with
> something like "input('Leave with Enter')" at the end.
>
> Now I've got a new computer with Windows 11 and I've installed Python
> 3.12.1. On my older machine it's Windows 10 and Python 3.11.5. Reading
> the Python documentation it seems my shebang lines should work as before
> - but they don't. The error message:
>
> "Unable to create process using 'C:\usr\bin\env\python
> "C:\Eigen\Src\launcher_versuche.py" ': Das System kann die angegebene
> Datei nicht finden."
>
> Without the "env" in the shebang line and only without it everything
> works as expected - but that's contrary to the documentation, isn't it?

This suggests a typo in the shebang line. Is there a space between env and python?

Barry


>
> Thank you for information,
> Sibylle
> --
> https://mail.python.org/mailman/listinfo/python-list
>

--
https://mail.python.org/mailman/listinfo/python-list
Re: Python 3.12.1, Windows 11: shebang line #!/usr/bin/env python3 doesn't work any more [ In reply to ]
What is the "command line" on your Windows 11?

On Windows 10 it usually is "cmd.exe" (Windows Command Prompt).
On Windows 11 it usually is the "Terminal" which is different from
cmd.exe.
--
https://mail.python.org/mailman/listinfo/python-list
Re: Python 3.12.1, Windows 11: shebang line #!/usr/bin/env python3 doesn't work any more [ In reply to ]
On 22/12/2023 13.36, Sibylle Koczian wrote:
> Hello,
>
> I always install Python on Windows in the same manner:
>
> - Python is not on the path,
> - it is installed for all users,
> - the Python Launcher is installed for all users,
> - the file types .py, .pyw etc. are associated with Python.
>
> My shebang line is usually "#!/usr/bin/env python3".

Disable BOM in your editor and re-save all files.

--
//Aho
--
https://mail.python.org/mailman/listinfo/python-list
Re: Python 3.12.1, Windows 11: shebang line #!/usr/bin/env python3 doesn't work any more [ In reply to ]
On 12/22/2023 7:36 AM, Sibylle Koczian via Python-list wrote:
> Hello,
>
> I always install Python on Windows in the same manner:
>
> - Python is not on the path,
> - it is installed for all users,
> - the Python Launcher is installed for all users,
> - the file types .py, .pyw etc. are associated with Python.
>
> My shebang line is usually "#!/usr/bin/env python3".
>
> This has always worked well. I could run Python scripts in a console
> window entering just the script name, by double clicking in the explorer
> or using WIN+r; the two last variants for GUI or for scripts with
> something like "input('Leave with Enter')" at the end.
>
> Now I've got a new computer with Windows 11 and I've installed Python
> 3.12.1. On my older machine it's Windows 10 and Python 3.11.5. Reading
> the Python documentation it seems my shebang lines should work as before
> - but they don't. The error message:
>
> "Unable to create process using 'C:\usr\bin\env\python
> "C:\Eigen\Src\launcher_versuche.py" ': Das System kann die angegebene
> Datei nicht finden."
>
> Without the "env" in the shebang line and only without it everything
> works as expected - but that's contrary to the documentation, isn't it?

How is a path for a linux location going to work on a Windows machine?
On Windows, when you click on a script the OS tries to find the program
that has been registered to run that script. Python would not have been
installed to "C:\usr\bin\env\python".

On my Windows 10 machine, Python scripts run without a shebang line.
Perhaps Windows 11 has added the ability to use one, but then you would
need to use the actual location of your Python executable.

If you have several Python installations, it's better to run Python
scripts using the "py" launcher, because Windows may have the wrong idea
about which version to use. The "where" command on my computer shows
Python 3.9, but I'm actually using Python 12.

--
https://mail.python.org/mailman/listinfo/python-list
Re: Python 3.12.1, Windows 11: shebang line #!/usr/bin/env python3 doesn't work any more [ In reply to ]
Am 22.12.2023 um 14:13 schrieb Barry:
>
>
>> On 22 Dec 2023, at 12:39, Sibylle Koczian via Python-list <python-list@python.org> wrote:
>>
>> ?Hello,
>>
>> I always install Python on Windows in the same manner:
>>
>> - Python is not on the path,
>> - it is installed for all users,
>> - the Python Launcher is installed for all users,
>> - the file types .py, .pyw etc. are associated with Python.
>>
>> My shebang line is usually "#!/usr/bin/env python3".
>>
>> This has always worked well. I could run Python scripts in a console
>> window entering just the script name, by double clicking in the explorer
>> or using WIN+r; the two last variants for GUI or for scripts with
>> something like "input('Leave with Enter')" at the end.
>>
>> Now I've got a new computer with Windows 11 and I've installed Python
>> 3.12.1. On my older machine it's Windows 10 and Python 3.11.5. Reading
>> the Python documentation it seems my shebang lines should work as before
>> - but they don't. The error message:
>>
>> "Unable to create process using 'C:\usr\bin\env\python
>> "C:\Eigen\Src\launcher_versuche.py" ': Das System kann die angegebene
>> Datei nicht finden."
>>
>> Without the "env" in the shebang line and only without it everything
>> works as expected - but that's contrary to the documentation, isn't it?
>
> This suggests a typo in the shebang line. Is there a space between env and python?
>
> Barry
>

Tried several variants with the same script:

#!/usr/bin/env python3
# That's how I wrote it for Windows 10 / Python 3.11. It works there.

#!/usr/bin/env python
#!/usr/bin/env/python

The error messages vary a little. This is a German Windows installation,
the two variants with the space produce the same German error message,
the third produces the message I've put into my first description.

The working variant on Windows 11 / Python 3.12 is "#!/usr/bin python".

Thank you,
Sibylle
--
https://mail.python.org/mailman/listinfo/python-list
Re: Python 3.12.1, Windows 11: shebang line #!/usr/bin/env python3 doesn't work any more [ In reply to ]
> On 22 Dec 2023, at 14:29, Sibylle Koczian <nulla.epistola@web.de> wrote:
>
> #!/usr/bin/env/python

That was what i thought you had and it will not work.

The BOM suggestion is worth trying.

Barry


--
https://mail.python.org/mailman/listinfo/python-list
Re: Python 3.12.1, Windows 11: shebang line #!/usr/bin/env python3 doesn't work any more [ In reply to ]
> On 22 Dec 2023, at 14:58, Christian Buhtz via Python-list <python-list@python.org> wrote:
>
> On Windows 11 it usually is the "Terminal" which is different from cmd.exe.

In terminal app you can run cmd.exe or powershell, so it is basically the same.

Barry


--
https://mail.python.org/mailman/listinfo/python-list
Re: Python 3.12.1, Windows 11: shebang line #!/usr/bin/env python3 doesn't work any more [ In reply to ]
On 12/22/2023 9:29 AM, Sibylle Koczian via Python-list wrote:
> Am 22.12.2023 um 14:13 schrieb Barry:
>>
>>
>>> On 22 Dec 2023, at 12:39, Sibylle Koczian via Python-list
>>> <python-list@python.org> wrote:
>>>
>>> ?Hello,
>>>
>>> I always install Python on Windows in the same manner:
>>>
>>> - Python is not on the path,
>>> - it is installed for all users,
>>> - the Python Launcher is installed for all users,
>>> - the file types .py, .pyw etc. are associated with Python.
>>>
>>> My shebang line is usually "#!/usr/bin/env python3".
>>>
>>> This has always worked well. I could run Python scripts in a console
>>> window entering just the script name, by double clicking in the explorer
>>> or using WIN+r; the two last variants for GUI or for scripts with
>>> something like "input('Leave with Enter')" at the end.
>>>
>>> Now I've got a new computer with Windows 11 and I've installed Python
>>> 3.12.1. On my older machine it's Windows 10 and Python 3.11.5. Reading
>>> the Python documentation it seems my shebang lines should work as before
>>> - but they don't. The error message:
>>>
>>> "Unable to create process using 'C:\usr\bin\env\python
>>> "C:\Eigen\Src\launcher_versuche.py" ': Das System kann die angegebene
>>> Datei nicht finden."
>>>
>>> Without the "env" in the shebang line and only without it everything
>>> works as expected - but that's contrary to the documentation, isn't it?
>>
>> This suggests a typo in the shebang line. Is there a space between env
>> and python?
>>
>> Barry
>>
>
> Tried several variants with the same script:
>
> #!/usr/bin/env python3
> # That's how I wrote it for Windows 10 / Python 3.11. It works there.
>
> #!/usr/bin/env python
> #!/usr/bin/env/python
>
> The error messages vary a little. This is a German Windows installation,
> the two variants with the space produce the same German error message,
> the third produces the message I've put into my first description.
>
> The working variant on Windows 11 / Python 3.12 is "#!/usr/bin python".

There is some important context that is missing here. Python on Windows
does not normally install to that location. That is not even a Windows
path, neither by directory name nor by path separators.

In addition, Powershell and cmd.exe do not use a shebang line, at least
through Windows 10. Instead, they use whatever executable has been
registered for a file extension. This may or may not be the version you
think. On my system, the OS will use Python 3.9, but actually the most
recent Python version on my system is Python 3.12. I can demonstrate the
difference: here is a tiny Python file with a shebang line, called
showme.py:

#! %USERPROFILE%\AppData\Local\Programs\Python\Python312\python.exe
import sys
print(sys.executable)

Run this with the "py" launcher:
py showme.py
# prints C:\Users\tom\AppData\Local\Programs\Python\Python312\python.exe

Run it by invoking just the script's name:
showme.py
# prints C:\Program Files\Python39\python.exe

In neither case is the shebang line used.

This makes me think that maybe the Linux subsystem for Windows is being
used here. If so, possibly the syntax for a shebang line has been
tightened up, or there's a typo. Either way, I would not automatically
assume that Windows (at least through Windows 10) ever used the shebang
line for launching these scripts.



--
https://mail.python.org/mailman/listinfo/python-list
Re: Python 3.12.1, Windows 11: shebang line #!/usr/bin/env python3 doesn't work any more [ In reply to ]
> On 23 Dec 2023, at 00:15, Thomas Passin via Python-list <python-list@python.org> wrote:
>
> In neither case is the shebang line used.

As i understand it, not in front of my windows box to check.
The handler for .py file extension is set to be the py.exe
It is py.exe that understands shebang lines.

Barry


--
https://mail.python.org/mailman/listinfo/python-list
Re: Python 3.12.1, Windows 11: shebang line #!/usr/bin/env python3 doesn't work any more [ In reply to ]
On 12/22/23 11:42, Thomas Passin via Python-list wrote:
> There is some important context that is missing here. Python on Windows
> does not normally install to that location. That is not even a Windows
> path, neither by directory name nor by path separators.

No, that's just the way the py launcher on Windows has always worked in
the past. This way you can take a script from a nix system and drop it
in Windows and it has half a chance of running through the launcher,
from Windows explorer, or by running py myscript.py at the command
propmpt. The Py launcher essentially ignores (or used to ignore) the
path in the shebang and focuses on what version of Python it should fire
up.
--
https://mail.python.org/mailman/listinfo/python-list
Re: Python 3.12.1, Windows 11: shebang line #!/usr/bin/env python3 doesn't work any more [ In reply to ]
On 12/22/23 07:02, Thomas Passin via Python-list wrote:
> On my Windows 10 machine, Python scripts run without a shebang line.
> Perhaps Windows 11 has added the ability to use one, but then you would
> need to use the actual location of your Python executable.

Yes if you associate .py or .pyw with python.exe (or pythonw.exe), then
things work as you describe. However it's no longer recommended to do
that.

Instead---and I think this is the default now when you install
python---you should associate both .py and .pyw files with the py
launcher (py.exe) and it will examine the shebang line of the script and
determine which version of python to run. As I said this should work
regardless of the path listed in the shebang. Note that the shebang is
meaningless to Windows itself, and Windows Explorer. It is only
meaningful to the py launcher. So it's customary to just use a
unix-style shebang in your python scripts. So either #!/usr/bin/python3
or #!/usr/bin/env python3 as you would in unix.

Using the py launcher as your Windows association with .py and.pyw files
you can have multiple versions of python installed and everything works
as it should, according to your shebang, just like on Unix.
--
https://mail.python.org/mailman/listinfo/python-list
Re: Python 3.12.1, Windows 11: shebang line #!/usr/bin/env python3 doesn't work any more [ In reply to ]
On 12/22/2023 7:19 PM, Barry wrote:
>
>
>> On 23 Dec 2023, at 00:15, Thomas Passin via Python-list <python-list@python.org> wrote:
>>
>> In neither case is the shebang line used.
>
> As i understand it, not in front of my windows box to check.
> The handler for .py file extension is set to be the py.exe
> It is py.exe that understands shebang lines.

Not on my system. It may depend on whether Python gets installed to
Program Files or to %USERPROFILE%/AppData/Local/Programs/Python. Python
3.9 is the last verson I installed to Program Files, and that's the
version that Windows thinks it should use to run Python files.

Run the little test program I posted. That will tell you which version
of Python the system wants to use.
--
https://mail.python.org/mailman/listinfo/python-list
Re: Python 3.12.1, Windows 11: shebang line #!/usr/bin/env python3 doesn't work any more [ In reply to ]
On Fri, 22 Dec 2023 17:27:58 -0700, Michael Torrie wrote:

> Using the py launcher as your Windows association with .py and.pyw files
> you can have multiple versions of python installed and everything works
> as it should, according to your shebang, just like on Unix.

Does that work with virtualenv or conda? I'm slowly getting up to speed
with those.
--
https://mail.python.org/mailman/listinfo/python-list
Re: Python 3.12.1, Windows 11: shebang line #!/usr/bin/env python3 doesn't work any more [ In reply to ]
On 12/22/2023 7:27 PM, Michael Torrie via Python-list wrote:
> On 12/22/23 07:02, Thomas Passin via Python-list wrote:
>> On my Windows 10 machine, Python scripts run without a shebang line.
>> Perhaps Windows 11 has added the ability to use one, but then you would
>> need to use the actual location of your Python executable.
>
> Yes if you associate .py or .pyw with python.exe (or pythonw.exe), then
> things work as you describe. However it's no longer recommended to do
> that.
>
> Instead---and I think this is the default now when you install
> python---you should associate both .py and .pyw files with the py
> launcher (py.exe) and it will examine the shebang line of the script and
> determine which version of python to run. As I said this should work
> regardless of the path listed in the shebang. Note that the shebang is
> meaningless to Windows itself, and Windows Explorer. It is only
> meaningful to the py launcher. So it's customary to just use a
> unix-style shebang in your python scripts. So either #!/usr/bin/python3
> or #!/usr/bin/env python3 as you would in unix.
>
> Using the py launcher as your Windows association with .py and.pyw files
> you can have multiple versions of python installed and everything works
> as it should, according to your shebang, just like on Unix.

I actually don't remember how to set up the association for Python
files. I just always type the "py" launcher anyway, as in

py -m pip instal ...

I think that the association with py.exe must only happen if you install
to Program Files. As I said in my previous post, Windows still sticks
with launching Python files with Python 3.9 even though I'm three
version beyond that. 3.9 is the only one I installed to Program Files.

In my experience one should always make sure to know what version of
Python is being used, at least if there is more than one version
installed on the computer. Even on Linux using a shebang line can be
tricky, because you are likely to get the system's version of Python,
and that often is not what you want. OTOH you don't want to go
symlinking python3 to some other version of python because then the OS
system may not work right. So either you have to specify the Python
version in the shebang, or just specify the right version on the command
line. In that case you might as well not have included the shebang line
at all.

I may be more sensitive to this issue because I run many different Linux
distros in VMs to check a few programs I support to make sure they can
run on Linux as well as Windows. What Linux, you ask? Well, who knows
what our users will use? So I'm always getting Python version
mix-and-match problems. The system will still be at Python 3.10 but I
need Python 3.11. The system uses Python 3.11 but we shouldn't (or
cannot) install our dependencies so we need a parallel install. Etc, etc.

It's just better not to make assumptions about which version of Python
will be running. Just specify it yourself when you can, and then you can
be sure.
--
https://mail.python.org/mailman/listinfo/python-list
Re: Python 3.12.1, Windows 11: shebang line #!/usr/bin/env python3 doesn't work any more [ In reply to ]
On 2023-12-22 22:56:45 -0500, Thomas Passin via Python-list wrote:
> In my experience one should always make sure to know what version of Python
> is being used, at least if there is more than one version installed on the
> computer. Even on Linux using a shebang line can be tricky, because you are
> likely to get the system's version of Python,

You are not "likely" to get the system's version of Python, you get the
version of Python you specify. If you specify "/usr/bin/python3", that's
the system's version of Python. If you specify something else, you get
something else. If you specify "/usr/bin/env python3", you get whatever
the user has in their PATH first.


> and that often is not what you want. OTOH you don't want to go
> symlinking python3 to some other version of python because then the OS
> system may not work right. So either you have to specify the Python
> version in the shebang,

This. In my considered opinion installed scripts should work regardless
pf the user's PATH, so they must have the correct interpreter in the
shebang. That specifying the correct shebang pulls in the complete
virtual environment is IMHO a great feature of Python.

I've written a small script "install-python" which basically just copies
a file and adjusts the shebang line.
<https://git.hjp.at:3000/hjp/install-python/src/branch/master/install-python>
for the use in Makefiles etc.

> or just specify the right version
> on the command line. In that case you might as well not have included the
> shebang line at all.

Right. However, that's not how scripts are usually invoked on Unix.
Using /usr/bin/env in the command line is supposed to fix that but of
course it assumes that your interpreter is actually called python3.

hp

--
_ | Peter J. Holzer | Story must make more sense than reality.
|_|_) | |
| | | hjp@hjp.at | -- Charles Stross, "Creative writing
__/ | http://www.hjp.at/ | challenge!"
Re: Python 3.12.1, Windows 11: shebang line #!/usr/bin/env python3 doesn't work any more [ In reply to ]
> On 23 Dec 2023, at 03:01, Thomas Passin via Python-list <python-list@python.org> wrote:
>
> Not on my system. It may depend on whether Python gets installed to Program Files or to %USERPROFILE%/AppData/Local/Programs/Python. Python 3.9 is the last verson I installed to Program Files, and that's the version that Windows thinks it should use to run Python files.
>
> Run the little test program I posted. That will tell you which version of Python the system wants to use.

I always install for all users and this what I get on my Windows 10 and 11 systems.
As you can see the shebang lines do what is expected based on the config of py.exe.

Maybe it works differently if you install for a single user only,
I do not have such a setup to test with.

Windows 10 output.

K:\shebang>py -0
-V:3.13 Python 3.13 (64-bit)
-V:3.13-32 Python 3.13 (32-bit)
-V:3.12 * Python 3.12 (64-bit)
-V:3.12-32 Python 3.12 (32-bit)
-V:3.11 Python 3.11 (64-bit)
-V:3.11-32 Python 3.11 (32-bit)
-V:3.10 Python 3.10 (64-bit)
-V:3.10-32 Python 3.10 (32-bit)
-V:3.9 Python 3.9 (64-bit)
-V:3.9-32 Python 3.9 (32-bit)
-V:3.8 Python 3.8 (64-bit)
-V:3.8-32 Python 3.8 (32-bit)
-V:3.7 Python 3.7 (64-bit)
-V:3.7-32 Python 3.7 (32-bit)
-V:3.6 Python 3.6 (64-bit)
-V:3.6-32 Python 3.6 (32-bit)
-V:3.5 Python 3.5
-V:3.5-32 Python 3.5-32
-V:3.4 Python 3.4
-V:3.4-32 Python 3.4-32
-V:2.7 Python 2.7
-V:2.7-32 Python 2.7-32

K:\shebang>type shebang_py2.py
#!/usr/bin/python2
from __future__ import print_function
import sys
print('I am python %r' % (sys.version_info,))

K:\shebang>py shebang_py2.py
I am python sys.version_info(major=2, minor=7, micro=17, releaselevel='final', serial=0)

K:\shebang>shebang_py2.py
I am python sys.version_info(major=2, minor=7, micro=17, releaselevel='final', serial=0)

K:\shebang>type shebang_py3.py
#!/usr/bin/python3
from __future__ import print_function
import sys
print('I am python %r' % (sys.version_info,))

K:\shebang>py shebang_py3.py
I am python sys.version_info(major=3, minor=12, micro=1, releaselevel='final', serial=0)

K:\shebang>shebang_py3.py
I am python sys.version_info(major=3, minor=12, micro=1, releaselevel='final', serial=0)

K:\shebang>type shebang_env_py3.py
#!/usr/bin/env python3
from __future__ import print_function
import sys
print('I am python %r' % (sys.version_info,))

K:\shebang>py shebang_env_py3.py
I am python sys.version_info(major=3, minor=12, micro=1, releaselevel='final', serial=0)

K:\shebang>shebang_env_py3.py
I am python sys.version_info(major=3, minor=12, micro=1, releaselevel='final', serial=0)

K:\shebang>type shebang_env_py3_10.py
#!/usr/bin/env python3.10
from __future__ import print_function
import sys
print('I am python %r' % (sys.version_info,))

K:\shebang>py shebang_env_py3_10.py
I am python sys.version_info(major=3, minor=10, micro=11, releaselevel='final', serial=0)

K:\shebang>shebang_env_py3_10.py
I am python sys.version_info(major=3, minor=10, micro=11, releaselevel='final', serial=0)

K:\shebang>assoc .py
.py=Python.File

K:\shebang>ftype Python.File
Python.File="C:\WINDOWS\py.exe" "%L" %*


Windows 11 output


: 11:52:10.36 K:\shebang
: \\BARNSTONE\barry> py -0
-V:3.12 * Python 3.12 (64-bit)
-V:3.12-32 Python 3.12 (32-bit)
-V:3.11 Python 3.11 (64-bit)
-V:3.11-32 Python 3.11 (32-bit)
-V:3.10 Python 3.10 (64-bit)
-V:3.9 Python 3.9 (64-bit)
-V:3.9-32 Python 3.9 (32-bit)
-V:3.8 Python 3.8 (64-bit)
-V:3.8-32 Python 3.8 (32-bit)

: 11:52:10.40 K:\shebang
: \\BARNSTONE\barry> type shebang_py2.py
#!/usr/bin/python2
from __future__ import print_function
import sys
print('I am python %r' % (sys.version_info,))

: 11:52:10.41 K:\shebang
: \\BARNSTONE\barry> py shebang_py2.py
No suitable Python runtime found
Pass --list (-0) to see all detected environments on your machine
or set environment variable PYLAUNCHER_ALLOW_INSTALL to use winget
or open the Microsoft Store to the requested version.

: 11:52:10.47 K:\shebang
: \\BARNSTONE\barry> type shebang_py3.py
#!/usr/bin/python3
from __future__ import print_function
import sys
print('I am python %r' % (sys.version_info,))

: 11:52:10.49 K:\shebang
: \\BARNSTONE\barry> py shebang_py3.py
I am python sys.version_info(major=3, minor=12, micro=0, releaselevel='final', serial=0)

: 11:52:10.52 K:\shebang
: \\BARNSTONE\barry> shebang_py3.py
I am python sys.version_info(major=3, minor=12, micro=0, releaselevel='final', serial=0)

: 11:52:10.58 K:\shebang
: \\BARNSTONE\barry> type shebang_env_py3.py
#!/usr/bin/env python3
from __future__ import print_function
import sys
print('I am python %r' % (sys.version_info,))

: 11:52:10.60 K:\shebang
: \\BARNSTONE\barry> py shebang_env_py3.py
I am python sys.version_info(major=3, minor=12, micro=0, releaselevel='final', serial=0)

: 11:52:10.65 K:\shebang
: \\BARNSTONE\barry> shebang_env_py3.py
I am python sys.version_info(major=3, minor=12, micro=0, releaselevel='final', serial=0)

: 11:52:10.72 K:\shebang
: \\BARNSTONE\barry> type shebang_env_py3_10.py
#!/usr/bin/env python3.10
from __future__ import print_function
import sys
print('I am python %r' % (sys.version_info,))

: 11:52:10.72 K:\shebang
: \\BARNSTONE\barry> py shebang_env_py3_10.py
I am python sys.version_info(major=3, minor=10, micro=11, releaselevel='final', serial=0)

: 11:52:10.77 K:\shebang
: \\BARNSTONE\barry> shebang_env_py3_10.py
I am python sys.version_info(major=3, minor=10, micro=11, releaselevel='final', serial=0)

: 11:52:10.83 K:\shebang
: \\BARNSTONE\barry> assoc .py
.py=Python.File

: 11:52:10.83 K:\shebang
: \\BARNSTONE\barry> ftype Python.File
Python.File="C:\WINDOWS\py.exe" "%L" %*

Barry

--
https://mail.python.org/mailman/listinfo/python-list
Re: Python 3.12.1, Windows 11: shebang line #!/usr/bin/env python3 doesn't work any more [ In reply to ]
On 12/22/23 20:56, Thomas Passin via Python-list wrote:
> It's just better not to make assumptions about which version of Python
> will be running. Just specify it yourself when you can, and then you can
> be sure.

Precisely, which is why the shebang is so useful, even on Windows with
py launcher. For example, set the shebang to:

#!/usr/bin/python3.6

And py launcher will always try to run it with Python 3.6.

--
https://mail.python.org/mailman/listinfo/python-list
Re: Python 3.12.1, Windows 11: shebang line #!/usr/bin/env python3 doesn't work any more [ In reply to ]
On 12/22/23 20:16, rbowman via Python-list wrote:
> On Fri, 22 Dec 2023 17:27:58 -0700, Michael Torrie wrote:
>
>> Using the py launcher as your Windows association with .py and.pyw files
>> you can have multiple versions of python installed and everything works
>> as it should, according to your shebang, just like on Unix.
>
> Does that work with virtualenv or conda? I'm slowly getting up to speed
> with those.

I don't know. I imagine py is aware of venv if you run it from the
command line within the activated venv. But I doubt it is if you launch
the python script by double-clicking on it from Explorer.

--
https://mail.python.org/mailman/listinfo/python-list
Re: Python 3.12.1, Windows 11: shebang line #!/usr/bin/env python3 doesn't work any more [ In reply to ]
> On 24 Dec 2023, at 00:54, rbowman via Python-list <python-list@python.org> wrote:
>
> Does that work with virtualenv or conda? I'm slowly getting up to speed
> with those.

Conda is its own thing, not need for py.exe.

Once you have created the venv you do not need py.exe as you will have pythob.exe in the venv bin folder.

Barry



--
https://mail.python.org/mailman/listinfo/python-list
Re: Python 3.12.1, Windows 11: shebang line #!/usr/bin/env python3 doesn't work any more [ In reply to ]
On Sun, 24 Dec 2023 22:55:34 +0000, Barry wrote:

>> On 24 Dec 2023, at 00:54, rbowman via Python-list
>> <python-list@python.org> wrote:
>>
>> Does that work with virtualenv or conda? I'm slowly getting up to speed
>> with those.
>
> Conda is its own thing, not need for py.exe.
>
> Once you have created the venv you do not need py.exe as you will have
> pythob.exe in the venv bin folder.


Thanks. That's what I have been doing and have never used py.exe. For
context Esri distributes ArcPy as a scripting language using 3.9. By
default the base install can't be modified so if you want additional
libraries or a tool like Spyder it has to be in a virtual.
--
https://mail.python.org/mailman/listinfo/python-list
Re: Python 3.12.1, Windows 11: shebang line #!/usr/bin/env python3 doesn't work any more [ In reply to ]
Apologies for top posting - my phone seems unable to do otherwise.

Here's my view - which may not be popular.

1. Py.exe is an awful idea.

2. Installing python in %PROGRAMFILES% is not a good idea

3. Installing Python from a Microsoft shop or server is a bad idea

4. Shebang lines are pretty much redundant now that most python interpreters are run from venvs

5. Shebang lines have never had a place in Windows

TL;DR

1. Py.exe is not a standard python thing and learning to rely on it is following Microsoft's marketing strategy. That strategy has served them brilliantly since the 1980s. They make their environment just different enough to force users to invest brainspace to make it work and thereby lock-in their users with their own muscle-memory. Very subtle. Not.

2. Installing Python in Microsoft's preferred location wasn't always "standard". Python downloaded from python.org always defaulted to C:\PythonXXX. I'm not saying that was a perfect location but at least it was (in my case still is) nicely visible for researching multiple different pythons. Putting deep in Program files does nothing other than hide it.

3. You cannot trust Microsoft. You can trust Python Software Foundation. Python from PSF works the same in all environments - or if not it is a bug. Python from Microsoft is tweaked to satisfy their aforementioned strategy of locking in users to Windows.

4. Shebang lines are a fallback if you don't wish to type the interpreter location before typing your script name. You must know your interpreter location to get the shebang line right. Shebangs were never intended as primary devices. They are linux/unix things.

5. Shebangs on Windows are a new opportunity for Microsoft to plough its own furrow. They are difficult to handle simply because of 4 above.

To finish this rant, I believe it is far better to aim for standardisation rather than subtle and annoying differences deliberately designed to supplant standards in favour of market dominance.

Merry Christmas all

Cheers

Mike




On 24 December 2023 3:35:42 am AEDT, Michael Torrie via Python-list <python-list@python.org> wrote:
>On 12/22/23 20:56, Thomas Passin via Python-list wrote:
>> It's just better not to make assumptions about which version of Python
>> will be running. Just specify it yourself when you can, and then you can
>> be sure.
>
>Precisely, which is why the shebang is so useful, even on Windows with
>py launcher. For example, set the shebang to:
>
>#!/usr/bin/python3.6
>
>And py launcher will always try to run it with Python 3.6.
>
>--
>https://mail.python.org/mailman/listinfo/python-list
--
https://mail.python.org/mailman/listinfo/python-list
Re: Python 3.12.1, Windows 11: shebang line #!/usr/bin/env python3 doesn't work any more [ In reply to ]
On Mon, 25 Dec 2023 at 15:42, Mike Dewhirst via Python-list
<python-list@python.org> wrote:
>
> Apologies for top posting - my phone seems unable to do otherwise.
>
> Here's my view - which may not be popular.

You're right about that part, anyhow :)

> 4. Shebang lines are pretty much redundant now that most python interpreters are run from venvs

Strongly dispute that. The rest. you're entitled to your opinions
(they happen to be wrong, but you're entitled to them :) ), but this
is a statement of fact that I would need to see some evidence for.

ChrisA
--
https://mail.python.org/mailman/listinfo/python-list
Re: Python 3.12.1, Windows 11: shebang line #!/usr/bin/env python3 doesn't work any more [ In reply to ]
Well spotted Chris. 4 was a generalisation based on my own circumstances.However, I'm not wrong about Microsoft motivationsM--(Unsigned mail from my phone)
-------- Original message --------From: Chris Angelico via Python-list <python-list@python.org> Date: 25/12/23 15:57 (GMT+10:00) To: Michael Torrie via Python-list <python-list@python.org> Subject: Re: Python 3.12.1, Windows 11: shebang line #!/usr/bin/env python3
doesn't work any more On Mon, 25 Dec 2023 at 15:42, Mike Dewhirst via Python-list<python-list@python.org> wrote:>> Apologies for top posting - my phone seems unable to do otherwise.>> Here's my view - which may not be popular.You're right about that part, anyhow :)> 4. Shebang lines are pretty much redundant now that most python interpreters are run from venvsStrongly dispute that. The rest. you're entitled to your opinions(they happen to be wrong, but you're entitled to them :) ), but thisis a statement of fact that I would need to see some evidence for.ChrisA-- https://mail.python.org/mailman/listinfo/python-list
--
https://mail.python.org/mailman/listinfo/python-list
Re: Python 3.12.1, Windows 11: shebang line #!/usr/bin/env python3 doesn't work any more [ In reply to ]
On 2023-12-25 12:36, Mike Dewhirst wrote:
>
> 3. You cannot trust Microsoft. You can trust Python Software Foundation. Python from PSF works the same in all environments - or if not it is a bug. Python from Microsoft is tweaked to satisfy their aforementioned strategy of locking in users to Windows.
>

I strongly disagree with this. I don't get all the irrational hate for
Microsoft that exists within the Linux community. In recent years,
Microsoft has made great contributions to the everyday life of Linux
users. VS Code is based on open source and available on Linux, .NET is
now on Linux, Windows has WSL2 and Visual Studio Linux development tools
to help you develop software for Linux, SQL Server (despite still being
commercial software except for the Express and Developer versions) is on
Linux, etc.
--
https://mail.python.org/mailman/listinfo/python-list

1 2 3  View All