Mailing List Archive

"py" command for Linux and Mac?
Hi folks.

I heard there's a Windows-like "py" command for Linux (and Mac?).

I'm finally getting to porting a particular project's Python 2.7 code to
3.x, and one of the first steps will probably be changing a lot of "python2
script.py" to use #!/usr/bin/env python2 and chmod +x. Then we can update
the scripts one at a time to use #!/usr/bin/env python3.

However, would this be Linux-and-Mac-only? I'm not at all sure this code
will ever move to Windows, but in case it does, would a "py" command work
on all 3 if I use #!/usr/bin/env py?

And if so, where can I find that "py" command for Linux and Mac?

I tried searching for it in Google and on Pypi, but unsurprisingly
searching for "py" gives a buzzillion hits on other things.

Thanks!
--
https://mail.python.org/mailman/listinfo/python-list
Re: "py" command for Linux and Mac? [ In reply to ]
On 2022-05-12 17:25, Dan Stromberg wrote:
> Hi folks.
>
> I heard there's a Windows-like "py" command for Linux (and Mac?).
>
> I'm finally getting to porting a particular project's Python 2.7 code to
> 3.x, and one of the first steps will probably be changing a lot of "python2
> script.py" to use #!/usr/bin/env python2 and chmod +x. Then we can update
> the scripts one at a time to use #!/usr/bin/env python3.
>
> However, would this be Linux-and-Mac-only? I'm not at all sure this code
> will ever move to Windows, but in case it does, would a "py" command work
> on all 3 if I use #!/usr/bin/env py?
>
> And if so, where can I find that "py" command for Linux and Mac?
>
> I tried searching for it in Google and on Pypi, but unsurprisingly
> searching for "py" gives a buzzillion hits on other things.
>
It's called the "Python Launcher"; you'll get more helpful results if
you search for that.
--
https://mail.python.org/mailman/listinfo/python-list
Re: "py" command for Linux and Mac? [ In reply to ]
On 5/12/22 10:25, Dan Stromberg wrote:
> Hi folks.
>
> I heard there's a Windows-like "py" command for Linux (and Mac?).
>
> I'm finally getting to porting a particular project's Python 2.7 code to
> 3.x, and one of the first steps will probably be changing a lot of "python2
> script.py" to use #!/usr/bin/env python2 and chmod +x. Then we can update
> the scripts one at a time to use #!/usr/bin/env python3.
>
> However, would this be Linux-and-Mac-only? I'm not at all sure this code
> will ever move to Windows, but in case it does, would a "py" command work
> on all 3 if I use #!/usr/bin/env py?

The py command (python lanucher) respects shebang lines.

https://docs.python.org/3/using/windows.html#python-launcher-for-windows


--
https://mail.python.org/mailman/listinfo/python-list
Re: "py" command for Linux and Mac? [ In reply to ]
On 2022-05-12, Mats Wichmann <mats@wichmann.us> wrote:
> On 5/12/22 10:25, Dan Stromberg wrote:
>> Hi folks.
>>
>> I heard there's a Windows-like "py" command for Linux (and Mac?).
>>
>> I'm finally getting to porting a particular project's Python 2.7 code to
>> 3.x, and one of the first steps will probably be changing a lot of "python2
>> script.py" to use #!/usr/bin/env python2 and chmod +x. Then we can update
>> the scripts one at a time to use #!/usr/bin/env python3.
>>
>> However, would this be Linux-and-Mac-only? I'm not at all sure this code
>> will ever move to Windows, but in case it does, would a "py" command work
>> on all 3 if I use #!/usr/bin/env py?
>
> The py command (python lanucher) respects shebang lines.

Linux by itself respects shebang lines, so you don't need a separate
launcher program. Just put e.g.:

#! /usr/bin/env python

at the top of your Python file.

--
In the beginning there was darkness and the darkness was without form
and void. And in addition to the darkness there was also me. And I moved
upon the face of the darkness and I saw that I was alone. ... ... ...
Let there be light. [Bomb 20; John Carpenter's Dark Star - 1974]
--
https://mail.python.org/mailman/listinfo/python-list
Re: "py" command for Linux and Mac? [ In reply to ]
On 5/12/22 11:59, De ongekruisigde wrote:
> On 2022-05-12, Mats Wichmann <mats@wichmann.us> wrote:
>> On 5/12/22 10:25, Dan Stromberg wrote:
>>> Hi folks.
>>>
>>> I heard there's a Windows-like "py" command for Linux (and Mac?).
>>>
>>> I'm finally getting to porting a particular project's Python 2.7 code to
>>> 3.x, and one of the first steps will probably be changing a lot of "python2
>>> script.py" to use #!/usr/bin/env python2 and chmod +x. Then we can update
>>> the scripts one at a time to use #!/usr/bin/env python3.
>>>
>>> However, would this be Linux-and-Mac-only? I'm not at all sure this code
>>> will ever move to Windows, but in case it does, would a "py" command work
>>> on all 3 if I use #!/usr/bin/env py?
>>
>> The py command (python lanucher) respects shebang lines.
>
> Linux by itself respects shebang lines, so you don't need a separate
> launcher program. Just put e.g.:

Dan knows this already. His question is about whether the shebang should
instead refer to a py launcher so that this script will run on Windows
or Linux.

And of course the answer given by the grandparent is that Dan should use
a normal linux shebang line in his scripts and on Windows the py
launcher will read that shebang and guestimate the proper python
interpreter to use and execute the script with that. Thus if I'm reading
this correctly, a Linux shebang line should function as expected on
Windows when python files are associated and launched with the py.exe
launcher, even though there's no such thing as /usr/bin/python3 on
Windows. Py launcher makes it work as if there was.


--
https://mail.python.org/mailman/listinfo/python-list
Re: "py" command for Linux and Mac? [ In reply to ]
On Sat, 21 May 2022 at 11:22, Michael Torrie <torriem@gmail.com> wrote:
> And of course the answer given by the grandparent is that Dan should use
> a normal linux shebang line in his scripts and on Windows the py
> launcher will read that shebang and guestimate the proper python
> interpreter to use and execute the script with that. Thus if I'm reading
> this correctly, a Linux shebang line should function as expected on
> Windows when python files are associated and launched with the py.exe
> launcher, even though there's no such thing as /usr/bin/python3 on
> Windows. Py launcher makes it work as if there was.
>

That's correct, and when the py.exe launcher was first, well,
launched, the main thrust of it was "it uses the shebang that you
already include for the sake of Unix systems". You don't need extra
directives to tell it what to do.

ChrisA
--
https://mail.python.org/mailman/listinfo/python-list