"py" command for Linux and Mac?

De ongekruisigde ongekruisigde at news.eternal-september.org
Thu May 12 13:59:51 EDT 2022


On 2022-05-12, Mats Wichmann <mats at 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]


More information about the Python-list mailing list